Created
April 28, 2019 23:01
-
-
Save jdh30/438afaed15d3bb7af3bfaedf54c4852b to your computer and use it in GitHub Desktop.
McCarthy's definition of LISP 1.5 in itself
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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