Right, there's an awful lot of Lisp actually working...
This commit is contained in:
parent
c3b327f760
commit
1f16241af7
31 changed files with 250 additions and 97 deletions
|
|
@ -1,2 +0,0 @@
|
|||
(COMMENT '(THIS FILE WILL CONTAIN FUNCTION DEFINITIONS TO BOOTSTRAP LISP FULLSTOP
|
||||
AT PRESENT WE HAVE NO COMMENT SYNTAX))
|
||||
|
|
@ -1 +0,0 @@
|
|||
(DEFUN LENGTH (L) (COND ((EQ NIL L) 0) (T (ADD1 (LENGTH (CDR L))))))
|
||||
|
|
@ -1,37 +1,77 @@
|
|||
;; Test comment
|
||||
((NIL . NIL)
|
||||
(T . T)
|
||||
;; many functions return 'F on fail, but to make this mean fail I'm binding
|
||||
;; it to NIL
|
||||
(F . NIL)
|
||||
;; Binding all system functions to NIL so that you can see on the OBLIST that
|
||||
;; they exist.
|
||||
(ADD1 . NIL)
|
||||
(AND . NIL)
|
||||
(APPEND . NIL)
|
||||
(APPLY . NIL)
|
||||
(ATOM . NIL)
|
||||
(CAR . NIL)
|
||||
(CDR . NIL)
|
||||
(CONS . NIL)
|
||||
(DEFINE . NIL)
|
||||
(DIFFERENCE . NIL)
|
||||
(EQ . NIL)
|
||||
(EQUAL . NIL)
|
||||
(EVAL)
|
||||
(FIXP . NIL)
|
||||
(INTEROP . NIL)
|
||||
(NUMBERP . NIL)
|
||||
(OBLIST . NIL)
|
||||
(PLUS . NIL)
|
||||
(PRETTY . NIL)
|
||||
(QUOTIENT . NIL)
|
||||
(READ . NIL)
|
||||
(REMAINDER)
|
||||
(RPLACA . NIL)
|
||||
(RPLACD . NIL)
|
||||
(SET . NIL)
|
||||
(SYSIN . NIL)
|
||||
(SYSOUT . NIL)
|
||||
(TIMES . NIL)
|
||||
)
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Beowulf Sysout file generated at 2023-03-30T09:40:36.483
|
||||
;; generated by simon
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
((NIL)
|
||||
(T . T)
|
||||
(F)
|
||||
(ADD1)
|
||||
(AND)
|
||||
(APPEND)
|
||||
(APPLY)
|
||||
(ATOM)
|
||||
(CAR)
|
||||
(CDR)
|
||||
(CONS)
|
||||
(COPY LAMBDA (X)
|
||||
(COND ((NULL X) (QUOTE NIL))
|
||||
((ATOM X) X)
|
||||
((QUOTE T) (CONS (COPY (CAR X)) (COPY (CDR X))))))
|
||||
(DEFINE)
|
||||
(DIFFERENCE)
|
||||
(DIVIDE LAMBDA (X Y) (CONS (QUOTIENT X Y) (CONS (REMAINDER X Y) (QUOTE NIL))))
|
||||
(ERROR)
|
||||
(EQ)
|
||||
(EQUAL)
|
||||
(EVAL)
|
||||
(FIXP)
|
||||
(GENSYM)
|
||||
(GET LAMBDA (X Y)
|
||||
(COND ((NULL X) (QUOTE NIL))
|
||||
((EQ (CAR X) Y) (CAR (CDR X)))
|
||||
((QUOTE T) (GET (CDR X) Y))))
|
||||
(GREATERP)
|
||||
(INTEROP)
|
||||
(INTERSECTION LAMBDA (X Y)
|
||||
(COND ((NULL X) (QUOTE NIL))
|
||||
((MEMBER (CAR X) Y) (CONS (CAR X) (INTERSECTION (CDR X) Y)))
|
||||
((QUOTE T) (INTERSECTION (CDR X) Y))))
|
||||
(LENGTH LAMBDA (L) (COND ((EQ NIL L) 0) (T (ADD1 (LENGTH (CDR L))))))
|
||||
(LESSP)
|
||||
(MEMBER LAMBDA (A X)
|
||||
(COND ((NULL X) (QUOTE F))
|
||||
((EQ A (CAR X)) (QUOTE T))
|
||||
((QUOTE T) (MEMBER A (CDR X)))))
|
||||
(MINUSP LAMBDA (X) (LESSP X 0))
|
||||
(NULL LAMBDA (X) (COND ((EQUAL X NIL) (QUOTE T)) (T (QUOTE F))))
|
||||
(NUMBERP)
|
||||
(OBLIST)
|
||||
(ONEP LAMBDA (X) (EQ X 1))
|
||||
(PAIR LAMBDA (X Y)
|
||||
(COND ((AND (NULL X) (NULL Y)) NIL)
|
||||
((NULL X) (ERROR 'F2))
|
||||
((NULL Y) (ERROR 'F3))
|
||||
(T (CONS (CONS (CAR X) (CAR Y)) (PAIR (CDR X) (CDR Y))))))
|
||||
(PLUS)
|
||||
(PRETTY)
|
||||
(PRINT)
|
||||
(PROP LAMBDA (X Y U)
|
||||
(COND ((NULL X) (U))
|
||||
((EQ (CAR X) Y) (CDR X))
|
||||
((QUOTE T) (PROP (CDR X) Y U))))
|
||||
(QUOTIENT)
|
||||
(READ)
|
||||
(REMAINDER)
|
||||
(REPEAT LAMBDA (N X)
|
||||
(COND ((EQ N 0) NIL)
|
||||
(T (CONS X (REPEAT (SUB1 N) X)))))
|
||||
(RPLACA)
|
||||
(RPLACD)
|
||||
(SET)
|
||||
(SUB1 LAMBDA (N) (DIFFERENCE N 1))
|
||||
(SYSIN)
|
||||
(SYSOUT)
|
||||
(TERPRI)
|
||||
(TIMES)
|
||||
(ZEROP LAMBDA (N) (EQ N 0)))
|
||||
|
|
|
|||
3
resources/mexpr/copy.mexpr.lsp
Normal file
3
resources/mexpr/copy.mexpr.lsp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
copy[x] = [null[x] -> NIL;
|
||||
atom[x] -> x;
|
||||
T -> cons[ copy[ car[x]]; copy[ cdr[x]]]]
|
||||
3
resources/mexpr/divide.mexpr.lsp
Normal file
3
resources/mexpr/divide.mexpr.lsp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
;; page 26
|
||||
|
||||
divide[x; y] = cons[ quotient[x; y]; cons[ remainder[x; y]; NIL]]
|
||||
|
|
@ -2,4 +2,4 @@ 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]; 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]]
|
||||
6
resources/mexpr/get.mexpr.lsp
Normal file
6
resources/mexpr/get.mexpr.lsp
Normal 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]]
|
||||
5
resources/mexpr/intersection.mexpr.lsp
Normal file
5
resources/mexpr/intersection.mexpr.lsp
Normal 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]]
|
||||
4
resources/mexpr/member.mexpr.lsp
Normal file
4
resources/mexpr/member.mexpr.lsp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
;; page 15
|
||||
member[a; x] = [null[x] -> F;
|
||||
eq[a; car[x]] -> T;
|
||||
T-> member[a; cdr[x]]]
|
||||
7
resources/mexpr/null.mexpr.lsp
Normal file
7
resources/mexpr/null.mexpr.lsp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
null[x] = [x = NIL -> T; T -> F]
|
||||
|
||||
(SETQ NULL
|
||||
'(LAMBDA (X)
|
||||
(COND
|
||||
((EQUAL X NIL) 'T)
|
||||
(T (QUOTE F)))))
|
||||
4
resources/mexpr/prop.mexpr.lsp
Normal file
4
resources/mexpr/prop.mexpr.lsp
Normal 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]]
|
||||
4
resources/mexpr/union.mexpr.lsp
Normal file
4
resources/mexpr/union.mexpr.lsp
Normal 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]]]
|
||||
|
|
@ -1 +0,0 @@
|
|||
null[x] = [x = NIL -> T; T -> F]
|
||||
1
resources/sexpr/conc.lsp
Normal file
1
resources/sexpr/conc.lsp
Normal file
|
|
@ -0,0 +1 @@
|
|||
;; TODO
|
||||
1
resources/sexpr/length.lsp
Normal file
1
resources/sexpr/length.lsp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(SETQ LENGTH '(LAMBDA (L) (COND ((EQ NIL L) 0) (T (ADD1 (LENGTH (CDR L)))))))
|
||||
11
resources/sexpr/pair.lsp
Normal file
11
resources/sexpr/pair.lsp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
;; PAIR is defined on page 60 of the manual, but the definition depends on both
|
||||
;; PROG and GO, and I haven't got those working yet; so this is a pure
|
||||
;; functional implementation.
|
||||
;; Return a list of pairs from lists `x` and `y`, required both to have the same
|
||||
;; length.
|
||||
|
||||
(DEFUN PAIR (X Y)
|
||||
(COND ((AND (NULL X) (NULL Y)) NIL)
|
||||
((NULL X) (ERROR 'F2))
|
||||
((NULL Y) (ERROR 'F3))
|
||||
(T (CONS (CONS (CAR X) (CAR Y)) (PAIR (CDR X) (CDR Y))))))
|
||||
6
resources/sexpr/repeat.lsp
Normal file
6
resources/sexpr/repeat.lsp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
;; REPEAT is not present in the Lisp 1.5 manual, but it's so simple and so
|
||||
;; useful that it seems a legitimate extension.
|
||||
|
||||
(DEFUN REPEAT (N X)
|
||||
(COND ((EQ N 0) NIL)
|
||||
(T (CONS X (REPEAT (SUB1 N) X)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue