Name and value of a symbol

Value of a constant is the constant

  Just as the expression, being a call of function, without a previous apostrophe represents value of expression, instead of expression, and atoms can be used for a designation of any values. It is already paid attention that before lisps constants (numbers and symbols true, false and nil) it is not necessary to put an apostrophe. As constants they designate themselves. If to enter a constant the interpreter as result will give out this constant:

>true  ; value of true is itself
true
>'true
  ; apostrophe superfluous
true
>nil
nil
>3.14
3.14

The symbol can designate any expression

  Symbols can be used as variables. In this case they can designate some expressions. Symbols initially do not have any value, as at constants. If, for example, we shall enter a symbol functions we shall receive the message on a mistake:

>functions
Error: Symbol functions have no value

  The interpreter here cannot calculate value of a symbol as it at it is not present.

SET calculates a name and connects it

  By means of function set the symbol can appropriate or connect with it some value. If, for example, we want, that the symbol functions designated base functions of the Lisp we shall enter:

>('functions set '(first rest cons atom eq))
(first rest cons atom eq)

  Now between a symbol functions and value (first rest cons atom eq) communication which is valid before the termination of job if, certainly, to this name function set will not appropriate new value is formed. After giving the interpreter can already calculate value of a symbol functions:

>functions
(first rest cons atom eq)

  Pay attention, that set calculates both of argument. If before the first argument there is no apostrophe by means of function set it is possible to appropriate value of a name which turns out by calculation. For example, a call

>((functions first) set '(to climb up in a head))
(to climb up in a head)

appropriates a variable first expression (to climb up in a head) , as the call (functions first) returns as value a symbol first which is used as actual argument of a call of function set:

>(functions first)  ; the first argument of the previous call
first
>first
  ; appropriated by function set value
(to climb up in a head)
>functions
(first rest cons atom eq)

SETQ connects a name, not calculating it

  Alongside with function set to connect a symbol with its value it is possible by means of function setq. This function differs from set that she calculates only the second argument. The letter reminds of automatic blocking calculation of the first argument q in a name of function. For example:

>(nil setq functions '(first rest cons atom eq))
nil

  At use of function setq disappears need for a sign on an apostrophe before the first argument.
  To check up, whether the atom is connected, it is possible by means of a predicate boundp which is true when the atom has any value:

>('withoutvalue boundp)
false
>('functions boundp)
(functions first rest cons atom eq)
>('true boundp)
  ; the constant is always connected
true

By-effect of pseudo-function

  Functions set and setq differ from other considered functions by that besides they matter, they possess also a by-effect. The effect of function consists in education of communication between a symbol and its value, and value of function is connected value. The symbol remains connected with the certain value until this value will not change.
  In the Lisp all actions return some value. Value is available even for such actions which basic applicability consists in realization of a by-effect, such, for example, as linkage of a symbol or a conclusion of results to a press. The functions possessing a by-effect, in the Lisp name pseudo-functions. We shall be all both for functions, and for pseudo-functions to use concept of function if only there is no special need to emphasize presence of a by-effect.
  The call of pseudo-function, for example the operator of transfer of management (and it too a call), from the point of view of use of its value can stand on a place of argument of other function. (In the programming languages based on the operational approach, it is usually impossible.)

>(nil list ('a set 3) 4)
(3 4)
>a
3
>(nil list (('b set 3) + 4) b)
  ; arguments are calculated in parallel
Error: Symbol b have no value

  In practical programming pseudo-function are useful and often are necessary, though in the theory, pure functional programming, they are not necessary.

The call of interpreter EVAL calculates value of value

  The interpreter of the Lisp is called eval, and it is possible the same as also other functions to cause it from the program. At usual programming to cause the interpreter it is not necessary, as this call implicitly is present at dialogue of the programmer from Lisp-systems.
  The superfluous call of the interpreter can to remove, for example, the effect of blocking of calculation or allows to find value of expression, i.e. to carry out double calculation:

>(nil quote (2 + 3))
(2 + 3)
>(nil eval (nil quote (2 + 3)))
5

  Here the interpreter calculates value of the first expression (nil quote (2 + 3)) , receiving as a result (2 + 3) . Further the call eval allows to start again the interpreter, and result will be value of expression (2 + 3) , i.e. 5 . Initial expression is processed in two stages. We still more some examples:

>(nil setq x '(a b c))
nil
>'x
x
>(nil eval 'x)
(a b c)
>(nil eval x)
  ; value x is (a b c)
Error: have no function link of b for number
>(nil eval ''(a b c))
(a b c)
>'(nil eval x)
(nil eval x)

   quote and eval operate in mutual opposite directions and cancel effect each other.
   eval is a universal function of the Lisp which can calculate any correctly made lisp expression. eval defines semantics lisp forms, i.e. defines, what symbols and forms together with what and that are meant also with what expressions matter.
  Semantics of the Lisp can compactly enough and apt be defined on the Lisp. The most part of system programs is written to the Lisp-systems on the Lisp, and the user can easily change system depending on the needs.

Basis cycle: READ-EVAL-PRINT

  With the interpreter of the Lisp at the uppermost, command level, it is possible to describe dialogue by a simple cycle:

(cout write '>)  ; writing of the invitation
(nil setq e (cin read))  ; input of expression
(nil setq v (nil eval e))  ; calculation of its value
(cout print v)  ; writing of result
(cout write '>)  ; recurrence of a cycle

  The interpreter of the Lisp answers a question asked to him and new value waits.