A session with XLISP-STAT basically consists of a conversation between you and the listener. The listener is the window into which you type your commands. When it is ready to receive a command it gives you a prompt. At the prompt you can type in an expression. You can use the mouse or the backspace key to correct any mistakes you make while typing in your expression. When the expression is complete and you type a return the listener passes the expression on to the evaluator. The evaluator evaluates the expression and returns the result to the listener for printing. The evaluator is the heart of the system.
The basic rule to remember in trying to understand how the evaluator works is that everything is evaluated. Numbers and strings evaluate to themselves:
> 1 1 > "Hello" "Hello" >Lists are more complicated. Suppose you type the list (+ 1 2 3) at the listener. This list has four elements: the symbol + followed by the numbers 1, 2 and 3. Here is what happens:
> (+ 1 2 3) 6 >A list is evaluated as a function application. The first element is a symbol representing a function, in this case the symbol + representing the addition function. The remaining elements are the arguments. Thus the list in the example above is interpreted to mean ``Apply the function + to the numbers 1, 2 and 3''.
Actually, the arguments to a function are always evaluated before the function is applied. In the previous example the arguments are all numbers and thus evaluate to themselves. On the other hand, consider
> (+ (* 2 3) 4) 10 >The evaluator has to evaluate the first argument to the function + before it can apply the function.
Occasionally you may want to tell the evaluator not to evaluate something. For example, suppose we wanted to get the evaluator to simply return the list (+ 1 2) back to us, instead of evaluating it. To do this we need to quote our list:
> (quote (+ 1 2)) (+ 1 2) >quote is not a function. It does not obey the rules of function evaluation described above: Its argument is not evaluated. quote is called a special form -- special because it has special rules for the treatment of its arguments. There are a few other special forms that we will need; I will introduce them as they are needed. Together with the basic evaluation rules described here these special forms make up the basics of the Lisp language. The special form quote is used so often that a shorthand notation has been developed, a single quote before the expression you want to quote:
> '(+ 1 2) ; single quote shorthandThis is equivalent to (quote (+ 1 2)). Note that there is no matching quote following the expression.
By the way, the semicolon `` ;'' is the Lisp comment character. Anything you type after a semicolon up to the next time you hit a return is ignored by the evaluator.