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-26 7:00

>>22

You know the drill. :)

>>19

Thanks, that looks interesting.

>>20

OK, so it's reasonable for f not to close over itself?

That's good, because so far I haven't had to make anything mutable.

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

It's up on bitbucket. It depends on an updated libsexp which exports O *mka(char *c) to make atoms, which was previously used internally. That's no change for the inline Unix port some kind anon posted above.

I plan to make a proper Unix branch at some point, but I haven't yet.

This is basically all it does:

+ if(strcmp(atomstr(car(f)), "CLOSURE") == 0){
+ env = splice(car(cdr(f)), env); /* XXX expensive! especially on every function call! */
+ args = evalargs(cdr(o), env);
+ env = args2env(car(cdr(cdr(f))), args, env);
+ return eval(car(cdr(cdr(cdr(f)))), env);
+ }
/* ... */
+ if(strcmp(a, "LAMBDA") == 0){
+ return cons(mka("CLOSURE"), cons(env, cdr(o)));
+ }


>>21

Ooh, good idea!

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