Giter Site home page Giter Site logo

maxbyz / purelisp.sh Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ytaki0801/purelisp.sh

0.0 0.0 0.0 1.54 MB

A Pure LISP interpreter written in shell script conformed to POSIX shell

License: Creative Commons Zero v1.0 Universal

Shell 98.17% Dockerfile 1.83%

purelisp.sh's Introduction

CC0

PureLISP.sh

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

demo

Purpose of this software

  • To use in education and research of basic LISP language processing easily
  • To use in ALL computer environments by running on a POSIX-conformant shell

BusyBox_ash NetBSD_sh dash NetBSD_ksh_(pdksh) ksh93%2frksh93 mksh oksh Bash yash bosh%2fpbosh

How to use

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

$ 

LISP Specification in this software

  • 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

    • default: prompt and pre-loading init file 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 file

See 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)

Shell Programming in this software

  • Conscells are firstly implemented to easy to program as a metacircular evaluator
  • Pseudo-Array and Stack implementation by using global variables
  • Using pattern-matching fully, to do S-expression lexical analysis especially

Bugs and TODO

  • Much more comments in the source code

License

The codes in this repository are licensed under CC0, Creative Commons Zero v1.0 Universal

purelisp.sh's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.