用sed实现Lisp:SedLisp

jopen 10年前

用 (GNU) sed实现Lisp。

如何使用

$ sed -f sedlisp.sed  # '>' won't be shown.  > (car (quote (a b c)))  a  > (cdr (quote (a b c)))  (b c)  > (cons 1 (cons 2 (cons 3 ())))  (1 2 3)  > (defun fact (n) (if (eq n 0) 1 (* n (fact (- n 1)))))  (lambda (n) (if (eq n 0) 1 (* n (fact (- n 1)))))  > (fact 10)  3628800  > (defun fib (n) (if (eq n 1) 1 (if (eq n 0) 1 (+ (fib (- n 1)) (fib (- n 2))))))  (lambda (n) (if (eq n 1) 1 (if (eq n 0) 1 (+ (fib (- n 1)) (fib (- n 2))))))  > (fib 12)  233  > (defun gen (n) ((lambda (x y) y) (define G n) (lambda (m) (define G (+ G m)))))  (lambda (n) ((lambda (x y) y) (define G n) (lambda (m) (define G (+ G m)))))  > (define x (gen 100))  (lambda (m) (define G (+ G m)))  > (x 10)  110  > (x 90)  200  > (x 300)  500

内置 Functions

  • car
  • cdr
  • cons
  • eq
  • atom
  • +, -, *, /, mod
  • neg?
  • print

特殊 Forms

  • quote
  • if
  • lambda
  • defun
  • define

项目主页:http://www.open-open.com/lib/view/home/1404115892624