[编译器试水]我的语言-plang (2)
plang的现状:
1. 有一些内置类型(int, double, char, string, 数组)
2. 有lambda和函数
3. 函数和lambda是first class
4. 数组可以用区间表示,比如[1..10] ['a' .. 'z']
5. 生成MSIL中间码,后边不管
6. scope的实现有个bug
7. 能算素数表
8. 简单的尾递归优化
截个图留念:
defun filter(f, x) { var a = Car(x); var b = Cdr(x); if a == [] then [] else if f(a) then [a] + filter(f,b) else filter(f,b); } defun isPrimeX(a, x) { var left = filter( $(n).{a % n == 0}, x); left == [] } defun PrimeX(x, result) { var a = Car(x); var b = Cdr(x); if a == [] then result else if isPrimeX(a, result) then PrimeX(b, result + [a]) else PrimeX(b, result); } defun Prime(x) { PrimeX(x, [2]); } Print("{0}", Prime([2..500]));
EOF