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.
make
rlwrap ./plisp
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 are either #t
or #f
.
booleans are eq?
literals:
#f #t
symbols cannot contain the characters '('
and ')'
and cannot start with a digit.
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 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\""
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 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 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!
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
creates a new closure.
examples
> (define curry+ (lambda (a) (lambda (b) (+ a b))))
#<interpreted closure>
> ((curry+ 5) 6)
11