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: Alexander Dubček 2015-03-25 17:30

Re: various syntax oddities - I've now written far more lines of Lisp interpreter than I have of Lisp, so my memory of how things work wasn't always the best.

Also, it turns out my clever idea for implementing special forms in Lisp code already exists, and is consideredharmful.
http://en.wikipedia.org/wiki/Fexpr

>>9,13

Oh!

Thanks, that also explains why some experiments I was trying in a Scheme interpreter didn't work as I expected.

>>10

Soon.

I just realized (but didn't test yet) that there's probably another problem.

(let ((x 10)(f (lambda () x))) (something f))
will work fine, since the lambda will be evalled and turned into a closure.

(let ((x 10)) (something (lambda () x)))
won't eval the lambda before passing it into something, so it won't close over x.

I don't know if I can fix this without walking the whole tree at every depth, looking for unclosed lambdas.

>>14
To demonstrate that recursion by name is broken.

Since g is set to f, one would expect it to recurse like f did.
But f wasn't in scope when f was defined, so it isn't part of the closure.
So even though I can still reference the function as g, to recurse it picks up f dynamically, which breaks when f was redefined.

I guess that's why defun was invented.

>>15,16

Oops, I was sort of aping cond there.

>>17

GC IS SHIT

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