User Tools

Special Operator TAGBODY


  • tagbody {tag | statement}**nil ====Arguments and Values==== * tag - a go tag; not evaluated. * statement - a compound form; evaluatedspecial. ====Description==== Executes zero or more statements in a lexical environment that provides for control transfers to labels indicated by the tags. The statements in a tagbody are evaluated in order from left to right, and their values are discarded. If at any time there are no remaining statements, tagbody returns nil. However, if (go tag) is evaluated, control jumps to the part of the body labeled with the tag. (Tags are compared with eql.) A tag established by tagbody has lexical scope and has dynamic extent. Once tagbody has been exited, it is no longer valid to go to a tag in its body. It is permissible for go to jump to a tagbody that is not the innermost tagbody containing that go; the tags established by a tagbody only shadow other tags of like name. The determination of which elements of the body are tags and which are statements is made prior to any macro expansion of that element. If a statement is a macro form and its macro expansion is an atom, that atom is treated as a statement, not a tag. ====Examples==== <blockquote> (let ((val nil)) (tagbody (setf val 1) (go point-a) (incf val 16) point-c (incf val 04) (go point-b) (incf val 32) point-a (incf val 02) (go point-c) (incf val 64) point-b (incf val 08)) val) <r>15 </r> (defun f1 (flag) (let ((n 1)) (tagbody (setf n (f2 flag #'(lambda () (go out)))) out (prin1 n)))) <r>F1</r> (defun f2 (flag escape) (ifflag (funcall escape) 2)) <r>F2 </r> (f1 nil) <o>2</o> <r>NIL </r> (f1 t) <o>1</o> <r>NIL</r> </blockquote> ====Affected By==== None. ====Exceptional Situations==== None. ====See Also==== * Special Operator GO ====Notes==== The macros listed below have implicit tagbodies. | do | do-external-symbols | dotimes | | do* | do-symbols | prog | | do-all-symbols | dolist | prog* | \issue{TAGBODY-TAG-EXPANSION:NO}