Right, there's an awful lot of Lisp actually working...

This commit is contained in:
Simon Brooke 2023-03-30 14:29:20 +01:00
parent c3b327f760
commit 1f16241af7
31 changed files with 250 additions and 97 deletions

View file

@ -0,0 +1,21 @@
;; see page 70 of Lisp 1.5 Programmers Manual; this expands somewhat
;; on the accounts of eval and apply given on page 13. This is M-expr
;; syntax, obviously.
;; apply
;; NOTE THAT I suspect there is a typo in the printed manual in line
;; 7 of this definition, namely a missing closing square bracket before
;; the final semi-colon; that has been corrected here.
apply[fn;args;a] = [
null[fn] -> NIL;
atom[fn] -> [get[fn;EXPR] -> apply[expr; args; a];
get[fn;SUBR] -> {spread[args];
$ALIST := a;
TSX subr4, 4};
T -> apply[cdr[sassoc[fn; a; λ[[]; error[A2]]]]; args a]];
eq[car[fn]; LABEL] -> apply[caddr[fn]; args;
cons[cons[cadr[fn];caddr[fn]]; a]];
eq[car[fn]; FUNARG] -> apply[cadr[fn]; args; caddr[fn]];
eq[car[fn]; LAMBDA] -> eval[caddr[fn]; nconc[pair[cadr[fn]; args]; a]];
T -> apply[eval[fn;a]; args; a]]

View file

@ -0,0 +1,3 @@
;; from page 5
[eq[car[x];A]->cons[B;cdr[x]];T->x]

View file

@ -0,0 +1,3 @@
copy[x] = [null[x] -> NIL;
atom[x] -> x;
T -> cons[ copy[ car[x]]; copy[ cdr[x]]]]

View file

@ -0,0 +1,3 @@
;; page 26
divide[x; y] = cons[ quotient[x; y]; cons[ remainder[x; y]; NIL]]

View file

@ -0,0 +1,3 @@
;; From page 6 of Lisp 1.5 Programmer's Manual
ff[x]=[atom[x] -> x; T -> ff[car[x]]]

View file

@ -0,0 +1,5 @@
gcd[x;y] = [x>y -> gcd[y;x];
rem[y;x] = 0 -> x;
T -> gcd[rem[y;x];x]]
;; gcd[x;y] = [x>y -> gcd[y;x]; remainder[y;x] = 0 -> x; T -> gcd[remainder[y;x];x]]

View file

@ -0,0 +1,6 @@
;; page 59; slightly modified because I don't at this stage want to
;; assume the existence of CADR
get[x; y] = [null[x] -> NIL;
eq[car[x]; y] -> car[cdr[x]];
T -> get[cdr[x]; y]]

View file

@ -0,0 +1,5 @@
;; page 15
intersection[x;y] = [null[x] -> NIL;
member[car[x]; y] -> cons[car[x]; intersection[cdr[x]; y]];
T -> intersection[cdr[x]; y]]

View file

@ -0,0 +1,4 @@
;; page 15
member[a; x] = [null[x] -> F;
eq[a; car[x]] -> T;
T-> member[a; cdr[x]]]

View file

@ -0,0 +1,7 @@
null[x] = [x = NIL -> T; T -> F]
(SETQ NULL
'(LAMBDA (X)
(COND
((EQUAL X NIL) 'T)
(T (QUOTE F)))))

View file

@ -0,0 +1,4 @@
;; page 59
prop[x;y;u] = [null[x] -> u[];
eq[car[x]; y] -> cdr[x];
T -> prop[cdr[x]; y; u]]

View file

@ -0,0 +1,4 @@
;; page 15
union[x; y] = [null[x] -> y;
member[car[x]; y] -> union[cdr[x]; y];
T -> cons[car[x]; union[cdr[x]; y]]]