3.1. Evaluation [sec_3-1]

3.1.1. Introduction to Environments
3.1.2. Symbols as Forms
3.1.2.1. Macro DEFINE-SYMBOL-MACRO
3.1.2.2. Dynamic Variables
3.1.3. Conses as Forms
3.1.4. Special Forms
3.1.4.1. Special operator EVAL-WHEN
3.1.4.2. Special operator THE
3.1.5. Function Forms
3.1.5.1. Function SYMBOL-FUNCTION
3.1.6. Macros DEFUN & DEFMACRO

3.1.1. Introduction to Environments [sec_3-1-1]

Macro EXT:THE-ENVIRONMENT. As in Scheme, the macro (EXT:THE-ENVIRONMENT) returns the current lexical environment. This works only in interpreted code and is not compilable!

Function (EXT:EVAL-ENV form &OPTIONAL environment). evaluates a form in a given lexical environment, just as if the form had been a part of the program that the environment came from.

3.1.2. Symbols as Forms [sec_3-1-2-1-1]

3.1.2.1. Macro DEFINE-SYMBOL-MACRO

The macro DEFINE-SYMBOL-MACRO establishes SYMBOL-MACROs with global scope (as opposed to SYMBOL-MACROs defined with SYMBOL-MACROLET, which have local scope).

The function EXT:SYMBOL-MACRO-EXPAND tests for a SYMBOL-MACRO: If symbol is defined as a SYMBOL-MACRO in the global environment, (EXT:SYMBOL-MACRO-EXPAND symbol) returns two values, T and the expansion; otherwise it returns NIL.

EXT:SYMBOL-MACRO-EXPAND is a special case of MACROEXPAND-1. MACROEXPAND-1 can also test whether a symbol is defined as a SYMBOL-MACRO in lexical environments other than the global environment.

3.1.2.2. Dynamic Variables [sec_3-1-2-1-1-2]

Undefined variables, i.e. variables which are referenced outside any lexical binding for a variable of the same name and which are not declared SPECIAL, are treated like dynamic variables in the global environment. The compiler SIGNALs a WARNING when it encounters an undefined variable.

3.1.3. Conses as Forms [sec_3-1-2-1-2]

Lists of the form ((SETF symbol) ...) are also treated as function forms. This makes the syntax (function-name arguments ...) consistent with the syntax (FUNCALL #'function-name arguments ...). It implements the item 7 of the [ANSI CL standard] issue FUNCTION-NAME:LARGE and the definition of function forms, and is consistent with the use of function names elsewhere in Common Lisp.

3.1.4. Special Forms [sec_3-1-2-1-2-1]

3.1.4.1. Special operator EVAL-WHEN

EVAL-WHEN also accepts the situations (NOT EVAL) and (NOT COMPILE).

Warning

The situations EVAL, LOAD and COMPILE are deprecated by the [ANSI CL standard], and they are not equivalent to the new standard situations :EXECUTE, :LOAD-TOPLEVEL and :COMPILE-TOPLEVEL in that they ignore the top-level form versus non-top-level form distinction.

3.1.4.2. Special operator THE

The special form (THE value-type form) is similar to CHECK-TYPE but does a type check only in interpreted code (no type check is done in compiled code - but see the EXT:ETHE macro) and does not allow interactive error correction by the user.

3.1.5. Function Forms [sec_3-1-2-1-2-3]

Constant LAMBDA-LIST-KEYWORDS(&OPTIONAL &REST &KEY &ALLOW-OTHER-KEYS &AUX &BODY &WHOLE &ENVIRONMENT)

3.1.5.1. Function SYMBOL-FUNCTION

(SETF (SYMBOL-FUNCTION symbol) object) requires object to be either a FUNCTION, a SYMBOL-FUNCTION return value, or a lambda expression. The lambda expression is thereby immediately converted to a FUNCTION.

3.1.6. Macros DEFUN & DEFMACRO

DEFUN and DEFMACRO are allowed in non-toplevel positions. As an example, consider the old ([CLtL1]) definition of GENSYM:

(let ((gensym-prefix "G")
      (gensym-count 1))
  (defun gensym (&optional (x nil s))
    (when s
      (cond ((stringp x) (setq gensym-prefix x))
            ((integerp x)
             (if (minusp x)
               (error "~S: index ~S is negative" 'gensym x)
               (setq gensym-count x)))
            (t (error "~S: argument ~S of wrong type" 'gensym x))))
    (prog1
      (make-symbol
        (concatenate 'string
          gensym-prefix
          (write-to-string gensym-count :base 10 :radix nil)))
      (incf gensym-count))))

See also Section 3.2.2.2, “Minimal Compilation ”.

Function EXT:ARGLIST. Function (EXT:ARGLIST name) returns the lambda list of the function or macro that name names and SIGNALs an ERROR if name is not FBOUNDP. It also SIGNALs an ERROR when the macro lambda list is not available due to the compiler optimization settings (see Section 3.3.6, “Declaration SPACE).

Variable CUSTOM:*SUPPRESS-CHECK-REDEFINITION*. When CUSTOM:*SUPPRESS-CHECK-REDEFINITION* is NIL, CLISP issues a WARNING when a function (macro, variable, class, etc) is redefined in a different file than its original definition. It is not a good idea to set this variable to T.

Variable CUSTOM:*DEFUN-ACCEPT-SPECIALIZED-LAMBDA-LIST*. When CUSTOM:*DEFUN-ACCEPT-SPECIALIZED-LAMBDA-LIST* is non-NIL, DEFUN accepts specialized lambda lists, converting type-parameter associations to type declarations:

(defun f ((x list) (y integer)) ...)

is equivalent to

(defun f (x y) (declare (type list x) (type integer y)) ...)

This extension is disabled by -ansi and by setting CUSTOM:*ANSI* to T, but can be re-enabled by setting CUSTOM:*DEFUN-ACCEPT-SPECIALIZED-LAMBDA-LIST* explicitly.


These notes document CLISP version 2.49Last modified: 2010-07-07