On page 173 of CLtL2 I read:
"PROG .. binds local variables .. permits use of .. RETURN
.. and .. GO .. In Common Lisp, these three operations have
been separated into three distinct constructs: LET, BLOCK and
TAGBODY. These three constructs may be used independently as
building blocks for other types of constructs."
However, I find that tags defined within LET, BLOCK and also LABELS
constructs doesn't work, even if theses are enclosed in a tagbody. The
tagbody has to be inside the LET, BLOCK and LABELS. Hence, none of
the test functions appended below work. This behavior is consistent
in all Lisps I have tried (Lucid, GCL and CLISP). Why is that ? From
what documentation should I have been able to deduce this behavior ?
Ingemar Hulthage
(DEFUN FOO ()
(TAGBODY
(LABELS ((PR (I) (PRINC (- I))))
(PR 1)
(GO 3)
(PRINC 2)
3 (PRINC 3)
)
)
)
(DEFUN BAR ()
(TAGBODY
(LET ((I 1))
(PRINC I)
(GO 3)
(PRINC 2)
3 (PRINC 3)
)
)
)
(DEFUN FOOBAR ()
(TAGBODY
(BLOCK NIL
(PRINC 1)
(GO 3)
(RETURN)
3 (PRINC 3)
)
)
)
The reason for this is that tags are only recognized at the top-level of
a TAGBODY form. Individual symbols or numbers have a different meaning
in the scope of a LET or BLOCK form.
A careful reasing of the next paragraph from CLtL2 reveals that
"An item in the [tagbody's] body may be a symbol or an integer, in
which case it is called a TAG, or an item in the body may be a list,
in which case it is called a STATEMENT."
If you have a LET form inside a TAGBODY, then the LET form is a
statement which is evaluated according to the rules for evaluating LET
forms. LET forms don't define a way of specifying tags, so there is no
way of interpreting symbols or integers as tags inside the LET.
--
Thomas A. Russ, USC/Information Sciences Institute ยทยทยท@isi.edu