8个版本

使用旧的Rust 2015

0.1.9 2017年7月2日
0.1.8 2017年6月25日

#775 in 编程语言

GPL-3.0 许可证

8KB
156

Teko

欢迎来到Teko编程语言。

此实现是用Rust编写的。

通过cargo安装teko: cargo install teko-rs

这里有一些代码片段可以尝试

help

将打印一条有用的提示:您可以使用以下方式查看作用域内的所有变量

(@variables)

字符串使用标准 space-and-parens-are-special 语法

(" hello world)

标准数学运算符可用

(+ 1 2 3)
(+ (* 8 9) 10)
(+ (/ 92138 9) 10)
(- (/ 12333 9) 10)

引用任意元素

(quote a b c)

输入值是否为符号?

(symbol? (head (quote a)))

Pair是新的Cons

(pair 4 (pair 1 ()))

(提示:尝试执行 (pair (pair 1 ())) 并查看结果)

Head是 car 或其他lisp中的 first

(head (quote a b c))

Tail是 cdr 或其他lisp中的 rest

(tail (quote a b c))

检查两个符号是否相同

(same? (head (quote a)) (head (quote b)))

定义和调用函数

(define x (fn (a b c) (@msleep 500) (* a b c)))
(x 1 2 3)

定义和调用宏,它们总是接受一个参数,即调用内部的所有语法树

(define my-macro (mo n (head n)))
(my-macro (write (+ 1 2 3)) (@msleep 300000) (write (* 8 9 10)))

错误处理

哦不,这太难了!~ 在Teko中不是这样

(define reason
	(wind
		(write (+ 1 2 () 8))
		(write (" If we get here then nothing bad happened, let's exit or something))))
(write (" OH NO! We unwound! Why?))
(write reason)
(error? reason)

我认为这是最酷的例子之一 :P

您还可以使用 unwind 手动恢复

(wind
	(@msleep 400)
	(unwind 800)
	(write (" this never runs)))

请注意,上面的 wind 表达式返回 800。您还可以返回错误

(wind
	(unwind (error (" Something bad happened, so we go back to the nearest wind)))
	(write (" and we don't run the rest of the block)))

堆栈跟踪很有用,也许您想自己制作

(wind
	(unwind (error (@trace)))
	(write (" and we don't run the rest of the block)))

就到这里吧!

依赖项

~3–12MB
~127K SLoC