Skip to content
This repository was archived by the owner on Dec 29, 2019. It is now read-only.

petelliott/plisp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

plisp

plisp is a scheme-like lisp interpreter (and hopefully soon compiler), written in C.

It uses the Boehm-Demers-Weiser garbage collector and will use gnu lightning.

useage

make
rlwrap ./plisp

plisp objects

integers

integers are signed 64bit integers.

only base 10, positive literals are currently supported.

integers are not eq? but are eqv?

literals:

0 1 1000 55

booleans

booleans are either #t or #f.

booleans are eq?

literals:

#f #t

symbols

symbols cannot contain the characters '(' and ')' and cannot start with a digit.

cons cells

cons cells are a pair of car and cdr.

example cons cell literal:

> '(1 . 2)
(1 . 2)

they are used to represent lists:

> '(1 . (2 . (3 . (4 . ()))))
(1 2 3 4)

strings

strings are immutable character arrays.

escape sequence result
\n newline
\t tab
\r carrige return
\e ansi escape
\\ slash
\" double quote
\nnn 3 digit octal sequence
\xhh 2 digit hex sequence

examples:

> "abcdefg"
"abcdefg"
> "\n\t\r\101\""
"\n\t\rA\""

special forms

quote

quote returns it's argument unevaluated.

the reader will interpret '<object> as (quote <object>)

examples:

> 'a
a
> '(1 2 3)
(1 2 3)
> '''a
(quote (quote a))

if

if evaluates and returns it's second argument if it's first argument is not #f otherwise it will evaluate and return it's third argument.

examples:

> (if 1 2 3)
2
> (if #f 2 3)
3
> (if #f (write 'a) (write 'b))
b

define

define creates a new variable in it's current scope, even if that variable already exists

it can also do the shorthand:

(define (a b c) (+ b c))
--->
(define a (lambda (b c) (+ b c)))

examples:

> (define a 5)
5
> a
5
> (define (b) a)
#<interpreted closure>
> (define a 8)
8
> a
8
> (b)
5

set!

set! changes the value of a variable

> (define a 5)
5
> (define b (lambda () a))
#<interpreted closure>
> (define c (lambda () (set! a 19)))
#<interpreted closure>
> (define a 8)
8
> (b)
5
> (c)
19
> (b)
19
> a
5

lambda

lambda creates a new closure.

examples

> (define curry+ (lambda (a) (lambda (b) (+ a b))))
#<interpreted closure>
> ((curry+ 5) 6)
11

About

a lisp

Resources

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published