XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

labels


Type:   -   special form (fsubr)
Source:   -   xlcont.c

Syntax

(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
returns - the value of the last expression

Description

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 'symbols' of the 'functions' and then sequentially execute the 'exprs'. The value of the last 'expr' evaluated is returned. When the 'labels' is finished execution, the 'symbols' that were defined will no longer exist.

Examples

(labels ((fuzz (x) (+ x x)))      ; a LABELS with a local function FUZZ
  (fuzz 2))                       ; returns 4

                                  ; FUZZ no longer exists
(fuzz 2)                          ; error: unbound function - FUZZ

                                  ; 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.

See the labels special form in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next