EVAL notation
June 8, 2008 | Filed Under Common Lisp - Touretzky
———————————————————
Chapter 3
———————————————————
Numbers, and the symbols NIL and T, evaluate to themselves:
1 -> 1
T -> T
NIL -> NIL
Evaluation rule for lists - the first element is the function to call, the rest are arguments to the function.
(DEFUN my-function (x)
(* x 2))
Evaluation rule for symbols - a symbol evaluates to the value of the variable it refers to
(setf kirk ‘a)
(setf spock ‘a)
(EQUAL kirk spock) -> T
(EQUAL ‘kirk ’spock) -> NIL
3 (1/2) ways to make lists:
‘(1 2 3) -> (1 2 3)
(LIST 1 2 3) -> (1 2 3)
(CONS 1 ‘(2 3)) -> (1 2 3)
(QUOTE (1 2 3)) -> (1 2 3)
A symbol is a block of 5 pointers. The first points to the name of the symbol, the 3rd to the function (the lambda function) which lies behind it.
Name and function can be extracted:
(SYMBOL-NAME ‘EQUAL) -> “EQUAL”
(SYMBOL-FUNCTION ‘EQUAL) -> #
(APPLY #’EQUAL ‘(12 17)) -> NIL
(APPLY #’CONS ‘(as (you like it))) -> (AS YOU LIKE IT)
Comments
Leave a Reply