.comment -*- Mode:TEXT; -*- .comment something about READ-EVAL-PRINT loops and EVAL .document EVAL - A very quick introduction to the Lisp evaluator. .tag EVAL Lesson EVAL, Version 1 Kent Pitman 2/1/80 revised by Victoria Pigman, 9/1/82 This is a VERY simple introduction to how Lisp evaluation works. At the appropriate time, we will discuss evaluation in greater detail. Lisps are initially in something called the READ-EVAL-PRINT loop. That means they read a form, evaluate it, and type the result. For example, if you type in a number, eg, 4 it will evaluate it (numbers evaluate to themselves) and type back the result (which will be 4). If you put something in parentheses, it is assumed by Lisp that the first thing inside the parentheses is a function and the other things that follow it are things to perform the function on. Hence,(+ 4 3) says to apply the + (addition) function to 4 and 3 (7 is typed back by Lisp). The objects to which functions are applied need not be simple. For example, (* 4 (+ 3 2)) says to multiply 4 with the result of adding 3 and 2. Note that Lisp ALWAYS returns a value of some sort back to whatever has called a function. This may mean returning the value to some other function that has called this function, so that, in the example above, the call to + returns a 5 back to the function * so that it can then multiply that value by its other argument and then have its value returned to whatever called it. In this case that would be the terminal, and 20 would printed on your terminal. This behaviour can be confusing in some places, notably in output functions like PRINT. Don't worry too much about it now; we'll mention it again later on. If you just want to get back a form literally, with no evaluation, you use the magic function QUOTE. Saying (QUOTE (+ 3 4)) does not return 7, it returns (+ 3 4). Saying (QUOTE (QUOTE (+ 3 4))) returns (QUOTE (+ 3 4)) and so on. There is a shorthand notation for (QUOTE something) and that is 'something. If you say 'ABC that is the same as typing (QUOTE ABC) and will return ABC. If you just type ABC, you will be asking Lisp to look up the value which is associated with the symbol ABC and return it. If no such value exists, Lisp will complain. White space (like spaces and tabs) is also unimportant in Lisp. Typing (+ 3 4) is the same as typing (+ 3 4) or (+ 3 4) so don't hesitate to put extra spaces in to make things more legible. .pause If you are used to programming in a non-lisp language, you may be familiar with the syntax FUNCTIONNAME(ARG1,ARG2,...). In Lisp you will have to remember that that won't work -- you always say (FUNCTIONNAME ARG1 ARG2 ...) with the function name inside the parentheses and white space between it and each of the arguments.(DO NOT USE commas, they mean something totally different to Lisp, that you should not worry about now.) This should be enough to keep you going through the other lessons. Good luck. .next OBJECT