LISP
歷史
. 解释器可以用来运行Lisp程序，或者更恰当的说为：“求值Lisp表达式” “ A form is an expression that can be evaluated. A form that is merely a constant has that constant as its value. If a form is a variable, then the value of the form is the S-expression that is bound to that variable at the time when we evaluate the form. …… A function can be simply a name. In this case its meaning must be previously understood. A function may be defined by using the lambda notation and establishing a correspondence between the arguments and the variables used in a form. If the function is recursive, it must be given a name by using a label. …… An interpreter or universal function is one that can compute the value of any given function applied to its arguments when given a description of that function. (Of course, if the function that is being interpreted has infinite recursion, the interpreter will recur infinitely also.) We are now in a position to define the universal LISP function. When  is given a function and a list of arguments for that function, it computes the value of the function applied to the arguments. LISP functions have S-expressions as arguments. In particular, the argument " " of the function  must be an S-expression. Since we have been writing functions as M-expressions, it is necessary to translate them into S-expressions. …… is defined by using two main functions, called  and. handles a function and its arguments, while  handles forms. Each of these functions also has another argument that is used as an association list for storing the values of bound variables and function names. …… A variable is a symbol that is used to represent an argument of a function. …… The formalism for variables in LISP is the Church lambda notation. The part of the interpreter that binds variables is called. When  encounters a function beginning with , the list of variables is paired with the list of arguments and added to the front of the a-list During the evaluation of the function, variables may be encountered. They are evaluated by looking them up on the a-list. If a variable has been bound several times, the last or most recent value is used. The part of the interpreter that does this is called. The following example will illustrate this discussion. Suppose the interpreter is given the following doublet: <tt> </tt> <tt> </tt> will give these arguments to. (Look at the universal function of Section I.) <tt> </tt> will bind the variables and give the function and a-list to. <tt> </tt> will evaluate the variables and give it to. <tt> </tt> The actual interpreter skips one step required by the universal function, namely,. …… It is sometimes assumed that a constant stands for itself as opposed to a variable which stands for something else. …… It seems more reasonable to say that one variable is more nearly constant than another if it is bound at a higher level and changes value less frequently. In LISP, a variable remains bound within the scope of the  that binds it. When a variable always has a certain value regardless of the current a-list, it will be called a constant. This is accomplished by means of the property list (p-list) of the variable symbol. Every atomic symbol has a p-list. When the p-list contains the indicator, then the symbol is a constant and the next item on the list is the value. searches p-lists before a-lists when evaluating variables, thus making it possible to set constants. …… An interesting type of constant is one that stands for itself. is an example of this. It can be evaluated repeatedly and will still be. , . , and other constants cannot be used as variables. …… The program form has the structure － <tt> </tt>(, list of program variables, sequence of statements and atomic' symbols…) …… Program variables are treated much like bound variables, but they are not bound by. The value of each program variable is  until it has been set to something else. To set a program variable, use the form. To set variable  to   write. is like  except that it quotes its first argument. Thus. is usually more convenient. and  can change variables that are on the a-list from higher level functions. The value of  or   is the value of its second argument. …… Every atomic symbol has a property list. When an atomic symbol is read in for the first time, a property list is created for it. A property list is characterized by having the special constant  (i.e., minus  ) as the first element of the list. The rest of the list contains various properties of the atomic symbol. Each property is preceded by an atomic symbol which is called its indicator. Some of the indicators are: <tt> </tt>  － the  print name of the atomic symbol for input-output use. <tt> </tt>  － S-expression defining a function whose name is the atomic symbol on whose property list the   appears. <tt> </tt>  － Function defined by a machine language subroutine. <tt> </tt>  － Permanent value for the atomic symbol considered as a variable. The atomic symbol  has two things on its property list － its , and an   that gives it a value of. Its property list looks like this: