A Pure LISP interpreter written in shell script conformed to POSIX shell
#PureLISP_sh
docker run --rm -it ytaki0801/plsh
This software is a Pure LISP interpreter written in shell script conformed to POSIX shell, inspired from John McCarthy's 1960 paper, Paul Graham's Common Lisp implementation, Lispkit Lisp, MIT's Structure and Interpretation of Computer Programs, Peter Norvig's Lispy, and The Julia Programming Language's femtolisp/tiny
Run the script to use REPL, like the following on busybox-w32 in a Command Prompt of Windows 10. You must type a blank line after input of LISP codes to eval.
C:\Users\TAKIZAWA Yozo\busybox>busybox.exe sh PureLISP.sh
S> (def reduce
(lambda (f L i)
(cond ((eq L nil) i)
(t (f (car L) (reduce f (cdr L) i))))))
reduce
S> (reduce cons '(a b c) '(d e f g))
(a b c d e f g)
S> (def rappend (lambda (x y) (reduce cons x y)))
rappend
S> (reduce rappend '((a b) (c d e) (f) (g h i)) '())
(a b c d e f g h i)
S> exit
C:\Users\TAKIZAWA Yozo\busybox>
Or, you can send a text file of LISP codes to PureLISP.sh with "-snl" or "-sl" option, prompt suppression mode, via redirection in a shell interpreter.
C:\Users\TAKIZAWA Yozo\busybox>busybox.exe sh
~/busybox $ cat examples/closure-stream.plsh
(def make-linear
(lambda (x)
(cons x (lambda () (make-linear (cons 'n x))))))
(def s (make-linear nil))
(car s)
(car ((cdr s)))
(car ((cdr ((cdr s)))))
(car ((cdr ((cdr ((cdr s)))))))
(car ((cdr ((cdr ((cdr ((cdr s)))))))))
(car ((cdr ((cdr ((cdr ((cdr ((cdr s)))))))))))
exit
~/busybox $ sh PureLISP.sh -snl < examples/closure-stream.plsh
make-linear
s
()
(n)
(n n)
(n n n)
(n n n n)
(n n n n n)
~/busybox $ exit
C:\Users\TAKIZAWA Yozo\busybox>
You can also try REPL by using Docker image created from Busybox base image.
$ docker run --rm -it ytaki0801/plsh
S> (def reverse-append
(lambda (x y)
(cond ((eq x nil) y)
(t (reverse-append
(cdr x)
(cons (car x) y))))))
reverse-append
S> (reverse-append '(a b c) '(x y z))
(c b a x y z)
S> (def reverse-list
(lambda (x)
(reverse-append x nil)))
reverse-list
S> (reverse-list '(a b c d e))
(e d c b a)
S> (def append-list
(lambda (x y)
(reverse-append (reverse-list x) y)))
append-list
S> (append-list '(a b c) '(x y z))
(a b c x y z)
S> exit
$
Built-in functions in Pure LISP: cons
, car
, cdr
, atom
, eq
Special forms in Pure LISP: quote
, cond
and lexically scoped lambda
Special form not in PureLISP: def
to bind variables in global environment
Special form not in Pure LISP: macro
to do meta-programming
Built-in function not in Pure LISP: length
to treat lists as numbers
Simple REPL with exit
command, comment notation ;
and the following exec options
init.plsh
in the current directory-snl
or -s
: no prompt and no pre-loading init file-sl
: no prompt and pre-loading init file-nl
: prompt and no pre-loading init fileSee init.plsh
and codes in examples
directory for details.
(FYI, firstly implemented referring to a John McCarthy's Original Lisp evaluator but now a SICP's one)
The codes in this repository are licensed under CC0, Creative Commons Zero v1.0 Universal