next up previous contents
Next: Macros Up: Improvements in Common Previous: Predicates

Control Structure

As mentioned in Section 4.3, block names and go targets are now properly lexically scoped.

A number of functions, macros and special forms have been modified to return multiple values when appropriate. These are

Functions can now be defined to return multiple values using the values  function. If a function is defined as

(defun f (x y) (values x y))
then it returns two values:
> (f 1 2)
1
2
Values beyond the first are ignored when the value of a function is passed as an argument:
> (list (f 1 2))
(1)
It is also possible to return no values; the implicit first value when used as a function argument is nil :
> (values)
> (list (values))
(NIL)
Returning no values is one way to suppress printing if no meaningful value is returned; for example, the pprint  function returns no values.

Several macros and special forms are available for capturing multiple values. You can collect them in a list with multiple-value-list ,

> (multiple-value-list (f 1 2))
(1 2)
access one specific value by position with nth-value ,
> (nth-value 0 (f 1 2))
1
> (nth-value 1 (f 1 2))
2
> (nth-value 2 (f 1 2))
NIL
bind them to variables with multiple-value-bind ,
> (multiple-value-bind (a b) (f 1 2) (list b a))
(2 1)
or pass them as arguments to a function with multiple-value-call ,
> (multiple-value-call #'+ (f 1 2))
3
Multiple values can also be produced with values-list  and captured with multiple-value-prog1  and multiple-value-setq .

The assignment macros psetf  and rotatef  and the macro typecase  are now available.

The assignment macro setf  has been re-implemented as a macro, both in the interpreter and a compiler. The function get-setf-method  has been added and is used both by setf  and by new versions of macros like push  and incf . The lmacsetf macro should now work with place forms that use apply .

The standard macro version of setf  introduces a number of temporary variables to avoid multiple evaluation of forms in a setf expression. This can slow down interpreted code (it does not affect compiled code since unnecessary bindings are optimized out). To reduce the impact of this, the special variable *simplify-setf*  can be set to a non nil value. When this variable is not nil , setf  substitutes the value expressions for these variables. In principle this can cause multiple evaluation of some subform, but it will not for any of the standard setf methods. This behavior is equivalent to the behavior of the previous internal version of setf . The setault value of *simplify-setf*  in the interpreter it t . The compiler should set it to nil , but does not do so yet.

The function special-form-p  has been added. It returns t if its symbol argument has a global function binding that is of type FSUBR; otherwise it returns nil .



next up previous contents
Next: Macros Up: Improvements in Common Previous: Predicates



Luke Tierney
Wed Feb 26 05:25:18 CST 1997