嵌入式技术
出品 | OSC开源社区(ID:oschina2013)
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
")
} {
(if (is (remainder i 3) 0) {
(print "fizz
")
} {
(if (is (remainder i 5) 0) {
(print "buzz
")
} {
(print i "
")
})
})
})
})
实现斐波那契数列
// 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)) "
")
})
更多示例代码:https://github.com/liam-ilan/crumb/tree/main/examples
标准库包括:IO、Comparisons、Logical Operators、Arithmetic 等。
Crumb 已在 GitHub 上开源,目前 200+ stars。

审核编辑:汤梓红
全部0条评论
快来发表一下你的评论吧 !