>>27Making the interpreter make 2 passes by defining f twice fixes the problem discussed in
>>5 and
>>20:
Welcome to Lisp
> (LET (
(f (LAMBDA (l) (IF (l (f (CDR l))) sameF)))
(g f)
(f (LAMBDA (x) (CAR x))))
(g (QUOTE (a b c))))
closure args: ((a b c))
closure args: ((b c))
b
> (LET (
(f (LAMBDA (l) (IF (l (f (CDR l))) sameF)))
(f (LAMBDA (l) (IF (l (f (CDR l))) sameF)))
(g f)
(f (LAMBDA (x) (CAR x))))
(g (QUOTE (a b c))))
closure args: ((a b c))
closure args: ((b c))
closure args: ((c))
closure args: (nil)
sameF
>
Results of testing the programs in
>>23:
> (LET ((x 10) (f (LAMBDA () x)) (g (LAMBDA (x f) (f))))
(g 20 f))
closure args: (20 (CLOSURE ((x 10)) nil x))
closure args: nil
10
> (LET ((x 10) (g (LAMBDA (x f) (f))))
(g 20 (LAMBDA () x)))
closure args: (20 (CLOSURE ((x 10) (g (CLOSURE ((x 10)) (x f) (f))) (x 10)) nil
x))
closure args: nil
10
Results of testing the programs in the readme:
Welcome to Lisp
> (QUOTE (a b c))
(a b c)
> (LET (
(f (LAMBDA (x) (CONS goats x)))
(g (LAMBDA (x) (CDR x))))
(f (g (QUOTE (1 2 3)))))
closure args: ((1 2 3))
closure args: ((2 3))
(goats 2 3)
> (LET ((f (LAMBDA (x) (IF (x (f (CDR x))) recursion!))))
(f (QUOTE (a b c d e))))
closure args: ((a b c d e))
closure args: ((b c d e))
closure args: ((c d e))
closure args: ((d e))
closure args: ((e))
closure args: (nil)
recursion!
> (LET (
(f (LAMBDA (x) (CAR (CDR x))))
(g (LAMBDA (f x) (f (CDR x)))))
(g f (QUOTE (a b c))))
closure args: ((CLOSURE nil (x) (CAR (CDR x))) (a b c))
closure args: ((b c))
c
> (LET ((f (LAMBDA (x) (CONS x y))))
(LET ((y world))
(f hello)))
closure args: (hello)
(hello . world)
> (LET ((f (LAMBDA (x) (LAMBDA (y) (CONS x y))))
(helloer (f hello)))
(helloer world))
closure args: (hello)
closure args: (world)
(hello . world)
> (LET ((CAR CDR)) (CAR (QUOTE (a b c))))
(b c)
> ()
nil
Excellent work.