Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
McCarthy's definition of LISP 1.5 in itself
; 20LOC to define a useful language
; However, no strings, IO, closure semantics or GC.
apply[fn;x;a] =
[atom[fn] -> [eq[fn;CAR] -> caar[x];
eq[fn;CDR] -> cdar[x];
eq[fn;CONS] -> cons[car[x];cadr[x]];
eq[fn;ATOM] -> atom[car[x]];
eq[fn;EQ] -> eq[car[x];cadr[x]];
T -> apply[eval[fn;a];x;a]];
eq[car[fn];LAMBDA] -> eval[caddr[fn];pairlis[cadr[fn];x;a]];
eq[car[fn];LABEL] -> apply[caddr[fn];x;cons[cons[cadr[fn];caddr[fn]];a]]]
eval[e;a] = [atom[e] -> cdr[assoc[e;a]];
atom[car[e]] ->
[eq[car[e],QUOTE] -> cadr[e];
eq[car[e];COND] -> evcon[cdr[e];a];
T -> apply[car[e];evlis[cdr[e];a];a]];
T -> apply[car[e];evlis[cdr[e];a];a]]
evcon[c;a] = [eval[caar[c];a] -> eval[cadar[c];a];
T -> evcon[cdr[c];a]]
evlis[m;a] = [null[m] -> NIL;
T -> cons[eval[car[m];a];evlis[cdr[m];a]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.