Campus LIsP (32K)

Discussion about ZX80 / ZX81 Software
User avatar
stefano
Posts: 542
Joined: Tue Dec 11, 2012 9:24 am
Contact:

Campus LIsP (32K)

Post by stefano »

EDIT: the binaries are now updated to support 180 objects, the former version was crashing when more than 126 objects were built.

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.
clisp.jpg
clisp.jpg (50.13 KiB) Viewed 9657 times
Attachments
clisp-zx81.zip
Campus LIsP, 32K version
(40.61 KiB) Downloaded 467 times
Last edited by stefano on Fri Apr 24, 2015 11:08 am, edited 1 time in total.
User avatar
stefano
Posts: 542
Joined: Tue Dec 11, 2012 9:24 am
Contact:

Campus LIsP (48K)

Post by stefano »

This is a variant for those rare 48k expanded systems.
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
Attachments
clisp-zx81-48k.zip
48K version, updated to support 180 objects
(12.42 KiB) Downloaded 436 times
clisp-win32.zip
CLISP compiled for windows, object space reservation close to the ZX81 version
(12.62 KiB) Downloaded 397 times
Last edited by stefano on Fri Apr 24, 2015 10:46 am, edited 1 time in total.
User avatar
stefano
Posts: 542
Joined: Tue Dec 11, 2012 9:24 am
Contact:

Re: Campus LIsP (32K)

Post by stefano »

This should show the extra power gained with the 'while' structure:

; 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))
)
(reverse w_w)
))


] (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))

square
] (mapcar 'square '(7 8 9 10))

(49 64 81 100)
User avatar
stefano
Posts: 542
Joined: Tue Dec 11, 2012 9:24 am
Contact:

Re: Campus LIsP (32K)

Post by stefano »

I can consider this project complete.
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 ;)
eliza.jpg
eliza.jpg (79.67 KiB) Viewed 9598 times
eliza-prg.jpg
(212.02 KiB) Downloaded 1014 times
Attachments
eliza.z81
(79.43 KiB) Downloaded 399 times
User avatar
stefano
Posts: 542
Joined: Tue Dec 11, 2012 9:24 am
Contact:

Re: Campus LIsP (32K)

Post by stefano »

I experimented a little more around my eliza simplification to squeeze out the space to make it smarter, but we're just too close to the memory limits:

](eliza)
(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))?
(yes)

((how can you be so sure) (you want to get answers))?
(good question)

(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)))?
(yes)

((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.

BYE


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 :mrgreen:
Attachments
eliza.zip
(1.37 KiB) Downloaded 383 times
clisp-zx81-32k-fast.zip
(20.57 KiB) Downloaded 363 times
User avatar
stefano
Posts: 542
Joined: Tue Dec 11, 2012 9:24 am
Contact:

Re: Campus LIsP (32K)

Post by stefano »

Doing a comparison between Campus Lisp and the ancient Spec Lisp for the ZX Spectrum (by Serious Software), I noticed that the latter chose to reduce the atom size to save memory (I also learnt how to deal with the turtle graphics and that old Lisp dialect, but it is another story).

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 :)
CLISP-16K.P
(14.76 KiB) Downloaded 371 times
...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 !
clisp_16k.png
clisp_16k.png (8.82 KiB) Viewed 9023 times
clisp_16k_2.png
clisp_16k_2.png (3.94 KiB) Viewed 9006 times
Last edited by stefano on Wed Dec 06, 2017 12:50 pm, edited 1 time in total.
User avatar
mrtinb
Posts: 1905
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Campus LIsP (32K)

Post by mrtinb »

Interesting. I didn't even see that LISP was made for ZX81. Thanks.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
siggi
Posts: 988
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: Campus LIsP (32K)

Post by siggi »

Hi Stefano
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).

Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
User avatar
mrtinb
Posts: 1905
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Campus LIsP (32K)

Post by mrtinb »

siggi wrote: Wed Dec 06, 2017 2:36 pm 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.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
stefano
Posts: 542
Joined: Tue Dec 11, 2012 9:24 am
Contact:

Re: Campus LIsP (32K)

Post by stefano »

Editing a function is not possible, you need to re-enter it and crossing fingers you should be able to issue the garbage collector with (gc) to wipe the old one.

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 !
CLISP-16K-SLOWMODE.P
Slower, flicker-free variant
(14.75 KiB) Downloaded 382 times
Post Reply