type: special form (fsubr) location: built-in source file: xlcont.c Common LISP compatible: yes supported on: all machines
(labels ( [ <function> ... ] ) <expr> ... ) <function> - a function definition binding which is of the form ( <symbol> <arg-list> <body> ) <symbol> - the symbol specifying the function name <arg-list> - the argument list for the function <body> - the body of the function <expr> - an expression
The LABELS special form is basically a local block construct that allows local <function> definitions followed by a block of code to evaluate. The first form after the labels is the 'binding' form. It contains a series of <functions>. LABELS allows the <functions> to be defined in a mutually recursive manner. (The similar FLET form does not allow this.) The LABELS form will go through and define the <symbol>s of the <functions> and then sequentially execute the <expr>'s. The value of the last <expr> evaluated is returned. When the LABELS is finished execution, the <symbol>'s that were defined will no longer exist.
(labels ( (fozz (x) (+ x x) )) ; a LABELS with FOZZ local func. (fozz 2)) ; returns 4 ; FOZZ no longer exists (fozz 2) ; error: unbound function - FOZZ ; ; an empty LABELS (labels () (print 'a)) ; prints A ; ; LABELS form including (labels ( (inc (arg) (est arg)) ; INC definition using EST (est (var) (* .1 var)) ) ; EST definition (inc 99) ) ; returns 9.9 ; ; FLET form including (flet ( (inc (arg) (est arg)) ; INC definition using EST (est (var) (* .1 var)) ) ; EST definition (inc 99) ; error: unbound function - EST
NOTE: FLET does not allow recursive definitions of functions. The LABEL special form does allow this.