makelisp是GNUmake的Lisp实现。
makelisp.mk是GNUmake中的Lisp解析器。
GNUmake包含两个内置函数:$(shell)和$(guile)。
使用$ make -f makelisp.mk LISP_PROGRAM='(car (quote (a b c)))'a$ make -f makelisp.mk LISP_PROGRAM='(cdr (quote (a b c)))'(b c)$ make -f makelisp.mk LISP_PROGRAM='(cons 1 (cons 2 (cons 3 ())))'(1 2 3)$ make -f makelisp.mk(defun fact (n) (if (eq n 0) 1 (* n (fact (- n 1)))))(fact 10)(defun fib (n) (if (eq n 1) 1 (if (eq n 0) 1 (+ (fib (- n 1)) (fib (- n 2))))))(fib 12)(defun gen (n) ((lambda (x y) y) (define G n) (lambda (m) (define G (+ G m)) G)))(define x (gen 100))(x 10)(x 90)(x 300)^Dfact3628800fib233genx110200500内置函数car
cdr
cons
eq
atom
+,-,*,/,mod
neg?
quote
if
lambda
defun
define
复杂示例FizzBuzz:
$ cat fizzbuzz.l | make -f makelisp.mk(lambda (n) (if (eq n 101) nil (if (print (if (eq (mod n 15) 0) FizzBuzz (if (eq (mod n 5) 0) Buzz (if (eq (mod n 3) 0) Fizz n)))) (fizzbuzz (+ n 1)) nil)))PRINT: 1PRINT: 2PRINT: Fizz...PRINT: 98PRINT: FizzPRINT: BuzznilSort:
$ (cat sort.l && echo '(sort (quote (4 2 99 12 -4 -7)))') | make -f makelisp.mk...(1 2 3 4 5 6 7)(-7 -4 2 4 12 99)
评论