Crumb 是最新开源的编程语言,发布后在 Reddit 的编程版块引起了广泛讨论。
正如标题所言,Crumb 是一门函数式编程语言,且没有“关键字”,一切皆函数 (0 keywords, everything is a function.)。其他特性包括提供垃圾回收 (GC)、动态类型、具有简洁的语法和详细的标准库。
示例代码
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/tree/main/examples
标准库包括:IO、Comparisons、Logical Operators、Arithmetic 等。