Skip to content

felipap/tiny-lisp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

f03lipe/tiny-lisp

A very very tiny EXCRUCIATINGLY SMALL (OK... maybe not THAT small: ~75 lines) interpreter for a minimal lisp dialect.

The fork won't hurt ya! Feel free to send a pull request.

Usage

To play with this, extend the primitive functions by editing libs.py.

What is this for?

Nothing, obviously.

License

MIT License.

What is supported

Nested s-expressions:

>> (+ (* (/ 3 4) 100) 45)
120

Anon functions: lambda or λ

>> ((λ (x y) (+ x y)) 3 4)
7
>> ((lambda m m) 0)
0

Conditions: cond

>> ((λ (x)
       (cond  ((% x 2) 'odd)
              (else 'even)))
    4)
'even

Literals: '

>> (list 'one '2 3)
("a", "2", 3)

Strings: doubles-quotes only

>> (list "a "3)
("a", 3)

Assigning: defines at the beggining of any block (evaluating to last element)

>> (+ ((define a 3) (* 10 a)) 5)
35

To define procedures, use lambda

>> ((define pow
            (lambda (x n)
                    (cond ((= n 1) x)
                          (else (* x (pow x (- n 1))))
                    )))
    (pow 2 4))
16.0

Wanna Help?

You can help by extending the libs.py to support more functions. Or optimize the interpreter.

About

So tiny you wouldn't call it lisp anyway... srsly, it's sexprs + lambda + define + cond.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages