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