Minilisp is a Lisp-like interactive environment for on-the-fly function prototyping. Based on the well-known paper by John McCarthy (http://www-formal.stanford.edu/jmc/recursive.pdf) Minilisp aims to be minimal, self-contained, and expandable.
Minilisp is a lexically-scoped Lisp language which provides very basic features and built-in functions. To summarize its features here is an almost complete list:
Minilisp supports three constant values:
- Logical true value:
#t
; - Logical false value:
#f
; - Nil:
()
, used both as the empty list and the list terminator.
Minilisp uses #f
for false and #t
for true, and supports the following logical operators:
- Logical and:
(and x y)
; - Logical or:
(or x y)
; - Logical not:
(not x)
.
Numbers can either be integers or doubles. The size of numbers is unlimited and different types of numeric values can be mixed together whenever a cast is possible. Minilisp supports the following arithmetic operations
- Addition:
(+ x1 x2 ... xn)
results in summing up all numbers appearing in the list; - Subtraction:
(- x y1 y2 ... yn)
results in subtracting the sum of ally
's fromx
; - Inversion:
(- x)
results in changing the sign tox
; - Multiplication:
(* x1 x2 ... xn)
results in multiplying all numbers in the list; - Division:
(/ x y1 y2 ... yn)
results in the division betweenx
and the product of ally
's; - Module:
(% x y)
results in the rest of the division between two integer values.
In Minilisp strings are everything enclosed in double quotes, like "Hello, World!"
.
As any Lisp dialect Minilisp supports out of the box the 5 basic Lisp functions
- Build a new cons-cell:
(cons a b)
, - Take the car of a cons-cell:
(car x)
- Take the cdr of a cons-cell:
(cdr x)
- Ask if a value is an atom or not:
(atom x)
- Ask if two atomic values are the same
(eq x y)
Minilisp supports additional built-in keywords with special evaluation rules
- Define a new global binding:
(define foo (cons #t #f))
results in binding(#t . #f)
to the symbolfoo
in the global environment; - Create new functions:
(lambda (n) (+ n 1))
results in a functions which add1
to any input number; - Create a temporary name (especially for recursion):
(label fact (lambda (n) (if (eq n 0) 1 (* n (fact (- n 1))))))
results in defining an anonymous factorial function. The symbolfact
doesn't get bind inside the global environment, but it can be used inside inline recursive definition; - Conditional evaluation:
(cond (c1 e1) (c2 e3) ... (cn ex))
results in evaluating the first expressionek
wheneverck
is the first true (#t
) condition; - If/then/else:
(if c e1 e2)
results in evaluatinge1
wheneverc
is true (#t
) ande2
wheneverc
is false (#f
). - Define an expression inside a local binding:
(let a x y)
results in evaluatingy
in a local environment where the symbola
takes the value ofx
; - Define a new list of objects:
(list x1 x2 ... xn)
results in the list(x1 x2 ... xn)
.
(define fact
(lambda (n)
(if (eq n 0) 1
(* n (fact (- n 1)))
)
)
)
(define fib
(lambda (n)
(if (< n 2) n
(+ (fib (- n 1)) (fib (- n 2)))
)
)
)