Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Lisp is fun!

Name: Alexander Dubček 2015-03-24 6:14

I wrote a toy Lisp interpreter this weekend. Programming is pretty much a video game!

https://bitbucket.org/dhoskin/thp

(LET ((f (LAMBDA (x) (IF (x (f (CDR x))) recursion!))))
(f (QUOTE (a b c d e))))

→ args: ((a b c d e))
→ args: ((b c d e))
→ args: ((c d e))
→ args: ((d e))
→ args: ((e))
→ args: (nil)
→ recursion!

Name: Anonymous 2015-03-25 22:21

>>18
I don't think there is a version of LET in any Lisp that lets you specify more than one definition for a variable. Neither LET, LET*, LETREC or LETREC* allow you do it.

The behaviour of thp seems reasonable:
1) Set f to a recursive definition where the f in f isn't bound to anything.
2) Set g to the first f
3) Redefine f (don't allow this)
4) Call g, which calls the first f which then calls the second f because the first f's f isn't bound. What else can it do? You've allowed f to be redefined before something else that refers to an f knows what it is.

If you insist on allowing f to be redefined, then you have to do multiple passes so recursive definitions still work.

For example, what happens if you define f twice with the same recursive definition before setting g to f?

ie:
(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))))


If you post your updated version I can try some stuff out.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List