函数式动态编程语言-Crumb
2023-08-29 21:45:27 阿炯

Crumb 是一门函数式编程语言,没有 “关键字”,一切皆函数 (0 keywords, everything is a function)。其他特性包括提供垃圾回收 (GC)、动态类型、具有简洁的语法和详细的标准库。采用C语言编写开发。


Crumb is a high level, functional, interpreted, dynamically typed, general-purpose programming language, with a terse syntax, and a verbose standard library.


标准库包括:IO、Comparisons、Logical Operators、Arithmetic、Control、Types、List and String 等。

Features:
Strictly no side effects* to help you write functional code
The ability to localize the effects of imported Crumb files.
Dynamic typing and garbage collection.
0 keywords, everything is a function.

All data in crumb is one of 6 different types:
string
integer
float
function/native function
list
void



示例代码

table = (map (range 10) {_ y ->
  <- (map (range 10) {item x ->
    <- (multiply (add x 1) (add y 1))
  })
})

(loop 100 {i ->
  i = (add i 1)
 
  (if (is (remainder i 15) 0) {
    (print "fizzbuzz\n")
  } {
    (if (is (remainder i 3) 0) {
      (print "fizz\n")
    } {
      (if (is (remainder i 5) 0) {
        (print "buzz\n")
      } {
        (print i "\n")
      })
    })
  })
})

实现斐波那契数列
// use a simple recursive function to calculate the nth fibonacci number
fibonacci = {n ->
  <- (if (is n 0) {<- 0} {
    <- (if (is n 1) {<- 1} {
      <- (add
        (fibonacci (subtract n 1))
        (fibonacci (subtract n 2))
      )
    })
  })
}

(until "stop" {state n ->
  (print (add n 1) "-" (fibonacci (add n 1)) "\n")
})

更多示例代码可见此处


最新版本:


项目主页:https://github.com/liam-ilan/crumb/