Please note that this tutorial presumes a little knowledge of lisp-like languages.
Assuming you have compiled the ZeptoLisp interpreter, go to its build directory and start it by typing:
$ ./zlisp
>Here you can enter lisp expressions.
First of all, ZeptoLisp uses lexical scoping. A variable named 'x' will refer to the definition of the variable called
'x' in the inner scope, where a scope can be:
> (def name expr)Where name is the name of the global variable and expr is a lisp expression. As an example to define a variable called x associated with the integer 9, you would write:
> (def x 9)From this point, the variable x will be defined till the end of the program.
> (let ((var1 var1-value) var2) expr)This expression is used to define the variables var1 and var2. var1 will be initialized to var1-value and var2 value will default to nil. var1 and var2 will be defined only inside expr, and an attempt to access them outside of it will result in an error.
> (let (a) (setq a 'c'))This defines the variable a and sets its value to the character 'c'.
> (let ((a 1) (b 2)) (list a b)) -> (1 2)
> (def x 0) -> 0 > (setq x (+ x 1)) -> 1
> (do expr1 expr2 ... exprn)The value of the last expression will be the value of the do expression.
> (let (a b) (do (setq a 10) (setq b 15) (+ a b)))
> (fun function-name (arg1 ... argn) body)function-name will be associated with the function itself in order to make recursive calls. body can be a single expression or a sequence of expressions. Functions can accept an indefinite number of arguments using the keyword &rest in the parameter list: the successive argument name will hold the list of optional arguments passed to the function.
> ((fun f (x) (+ x 1)) 9) -> 10Creates a function wich takes one argument and returns the argument incremented by one, and directly calls the function passing 9 as the argument.
> (fun inc (x) (+ x 1)) -> function > (inc 10) -> 11 > (fun cons-9 (&rest r) (cons 9 r)) -> function > (cons-9 0 1 2 3) -> (9 0 1 2 3)This creates the same function and then calls it through the variable inc.
> (macro name (arg1 ... argn) expr)This defines a macro named 'name'. arg1 ... argn are the names of the arguments.
> (def n 0) -> 0 > (while (<= n 5) (do (print n) (setq n (+ n 1)))) 0 1 2 3 4 5 -> nilFor loops:
> (for (i 0 6 (+ i 1)) (print i)) 0 1 2 3 4 5 -> nilTimes loops:
> (times (i 6) (print i)) 0 1 2 3 4 5 -> nil