This is a more stable release of the already announced LISP port (see development section).
The original idea is by Hirotsugu Kakugawa, which introduced a very smart approach based on altering the LONG datatype to insert tags with no extra memory cost.
I extended the original project using mostly the Common LISP syntax as reference model.
This updated version features an extra function (inspired on the "while" simplification used by EMACS LISP) permitting to write iteractive loops as an alternate approach to the memory consuming recursion.
Sadly the memory size permits a function to recursively call itself no more than 40 times.
LISP is a very interesting language, i.e. this implementation does not handle strings but it is still possible to handle named objects, thus have a human readable input/output.
I'm posting a standard version (which will init the language with a basic function set and clean memory) plus a version suitable to LOAD/SAVE the current memory status.
This latter version does not initialize the program/data memory block, so you must load a preset one before running the interpreter; lisp.sav contains only the basic setup, lisp-full.sav is much bigger and complete (pls refer to library.lisp for details).
There is plenty of tutorials online, the simplest examples can be adapted.
- Campus LIsP, 32K version
- (40.61 KiB) Downloaded 252 times
It permits 4 times the number of recursive calls compared to the 32K version.
The LOAD/SAVE option is fully compatible to the 32K one, in both the cases you need to keep just the first 10300 bytes at positon 32768
Useful trick: the CLISP interpreter can be easily compiled on modern computers. It permits to test your LISP programs before typing them on a ZX81.
I'm attaching a Windows port, the programs can be directly pasted in the console window.
The current library includes more than 100 functions:
read, eval, gc, cons, car, cdr, quit, defun, quote, setq, eq, null, consp, symbolp, numberp, princ, terpri, rplaca, rplacd, progn, cond, or, not, if, list, +, -, *, /, >, <, and, divide, lambda, while, >=, <=, comment, zerop, atom, random, rem, 1+, 1-, equal, =, print, apply, positivep, negativep, evenp, oddp, iseven, listp, nill, expt, abs, gcd, l-gcd, -l-gcd, lcm, l-lcm, -l-lcm, endp, first, rest, nthcdr, nth, last, reverse, --reverse, append, revappend, memq, member, list-length, union, intersection, copy-list, copy-tree, subst, tree, assv, obj, alist, caar, cddr, cadr, cdar, second, third, caddr, cadar, cadadr, set-difference, count-leaves, acons, sublis, pairlis, most-positive-fixnum, most-negative-fixnum, butlast, sqrt
- 48K version, updated to support 180 objects
- (12.42 KiB) Downloaded 253 times
- CLISP compiled for windows, object space reservation close to the ZX81 version
- (12.62 KiB) Downloaded 231 times
; execute a given function for each list element
; it works also on list of lists
(defun mapcar (f l)
(progn (setq y_y l) (setq w_w nil)
(while (not (null y_y))
(if (consp y_y)
(setq z_z (list f '(car y_y)))
(setq z_z (list f (car y_y)))
(setq w_w (cons (eval z_z) w_w))
(setq y_y (cdr y_y))
] (mapcar 'reverse '((3 4) (5 6 7) (7 8 9 10)))
((4 3) (7 6 5) (10 9 8 7))
] (mapcar 'car '((3 4) (5 6 7) (7 8 9 10)))
(3 5 7)
] (defun square (x) (* x x))
] (mapcar 'square '(7 8 9 10))
(49 64 81 100)
I fixed a bug limiting the number of objects to 127 when there was space for 180 (I'll refresh the packages above).
Recursion can be very slow on a zx81 and the memory limit is a pain but I think I won the challenge to get a LISP version of the ELIZA program running in a ZX81
- (79.43 KiB) Downloaded 234 times
(what is the meaning of life)
((i keep my opinion on) (what is the meaning of life) (for myself)).
(this does not help me)
(why (have you decided that to) (help you) (is important for you))?
(i want to get answers)
((do you really) (want to get answers))?
((how can you be so sure) (you want to get answers))?
(but why be concerned about it).
(it is you asking)
(just tell me how you feel).
(i feel good)
(sometimes i feel the same way).
(nice to hear)
(tell me more).
(you are only a stupid computer)
((so you think) ((i am) (only a stupid computer)))?
((how can you be so sure) ((i am) (only a stupid computer)))?
(what do you think you are)
((do you really) (think me are))?
(i knew you'd have made a mistake sooner or later!)
no memory. abort.
By the way I compared it to the existing BASIC implementation and I noticed that, even if awfully slow, it is still faster, even if the BASIC version runs in FAST mode !
...which made me remind that it is possible to kick the CPU with the FAST option
It makes the maths results very poor but almost halves the memory requirements for the lists.
By doing so I was able to get a crap but funny version for the standard 16K expansion
...as you see you have even bonus graphics extension but very little memory to use it.
Be careful, a (cls) will position the graphics 'turtle' on the left-bottom corner, so this picture is slightly misleading !
is it possible to edit a function which has been typed in incorrectly?
Does the 48 K version have only data above 48K? On most zeddies (except ZxMore) running machine code above 48K is not possible (above 32K only after M1NOT modification).
Maybe LISP "code" is data if Campus LIsP is implemented as an interpreter like BASIC.
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
The Lisp is an Interpreter, MRTINB is right.
For the 16K I'm adding a less annoying (but slower) variant. Speed is not an issue here, there's so little memory available, so long programs won't exist !