User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cl:special_operators:return-from [2017/05/01 21:00] (current)
Line 1: Line 1:
 +====== Special Operator RETURN-FROM ======
 +
 +====Syntax====
 +  * **return-from** //name [result]//
 +
 +====Arguments and Values====
 +  * //name// - a //​[[CL:​Glossary:​block tag]]//; not evaluated.
 +  * //result// - a //​[[CL:​Glossary:​form]]//;​ evaluated. The default is **[[CL:​Constant Variables:​nil]]**.
 +
 +====Description====
 +Returns control and //​[[CL:​Glossary:​multiple values]]// from a lexically enclosing //​[[CL:​Glossary:​block]]//​.
 +
 +A **[[CL:​Special Operators:​block]]** //​[[CL:​Glossary:​form]]//​ named //name// must lexically enclose the occurrence of **return-from**;​ any //​[[CL:​Glossary:​value|values]]//​ //​[[CL:​Glossary:​yield|yielded]]//​ by the //​[[CL:​Glossary:​evaluation]]//​ of //result// are immediately returned from the innermost such lexically enclosing //​[[CL:​Glossary:​block]]//​.
 +
 +The transfer of control initiated by **return-from** is performed as described in \secref\TransferOfControl.
 +
 +====Examples====
 +<​blockquote>​
 +([[CL:​Special Operators:​block]] alpha 
 +  (return-from alpha) ​
 +  1) <​r>​[[CL:​Constant Variables:​NIL]] </r>
 +([[CL:​Special Operators:​block]] alpha (return-from alpha 1) 2) <r>1 </r>
 +([[CL:​Special Operators:​block]] alpha (return-from alpha ([[CL:​Functions:​values]] 1 2)) 3) <r>1
 +2 </r>
 +([[CL:​Special Operators:​let]] ((a 0)) 
 +  ([[CL:​Macros:​dotimes]] (i 10) 
 +    ([[CL:​Macros:​incf]] a) 
 +    ([[CL:​Macros:​when]] ([[CL:​Functions:​oddp]] i) ([[CL:​Macros:​return]]))) ​
 +  a) <r>2 </r>
 +([[CL:​Macros:​defun]] temp (x) 
 +  ([[CL:​Macros:​when]] x (return-from temp '​dummy)) ​
 +  44) <​r>​TEMP </r>
 +(temp [[CL:​Constant Variables:​nil]]) <r>44 </r>
 +(temp [[CL:​Constant Variables:​t]]) <​r>​DUMMY </r>
 +([[CL:​Special Operators:​block]] out ([[CL:​Special Operators:​flet]] ((exit (n) (return-from out n))) ([[CL:​Special Operators:​block]] out (exit 1))) 2) <r>1 </r>
 +([[CL:​Special Operators:​block]] [[CL:​Constant Variables:​nil]] ​
 +  ([[CL:​Special Operators:​unwind-protect]] ​
 +      (return-from [[CL:​Constant Variables:​nil]] 1)
 +    (return-from [[CL:​Constant Variables:​nil]] 2))) <r>2 </r>
 +([[CL:​Macros:​dolist]] (flag '​([[CL:​Constant Variables:​nil]] [[CL:​Constant Variables:​t]])) ​
 +  ([[CL:​Special Operators:​block]] [[CL:​Constant Variables:​nil]] ​
 +    ([[CL:​Special Operators:​let]] ((x 5)) 
 +      ([[CL:​Symbols:​declare]] ([[CL:​Declarations:​special]] x)) 
 +      ([[CL:​Special Operators:​unwind-protect]] ​
 +          (return-from [[CL:​Constant Variables:​nil]])
 +        ([[CL:​Functions:​print]] x))))
 +  ([[CL:​Functions:​print]] '​here))
 +<o>5
 +HERE
 +5
 +HERE </o>
 +<​r>​[[CL:​Constant Variables:​NIL]] </r>
 +([[CL:​Macros:​dolist]] (flag '​([[CL:​Constant Variables:​nil]] [[CL:​Constant Variables:​t]])) ​
 +  ([[CL:​Special Operators:​block]] [[CL:​Constant Variables:​nil]] ​
 +    ([[CL:​Special Operators:​let]] ((x 5)) 
 +      ([[CL:​Symbols:​declare]] ([[CL:​Declarations:​special]] x))
 +    ([[CL:​Special Operators:​unwind-protect]] ​
 +        ([[CL:​Macros:​when]] flag (return-from [[CL:​Constant Variables:​nil]]))
 +      ([[CL:​Functions:​print]] x)))) 
 +  ([[CL:​Functions:​print]] '​here))
 +<o>5
 +HERE
 +5
 +HERE </o>
 +<​r>​[[CL:​Constant Variables:​NIL]] </r>
 +</​blockquote>​
 +
 +The following has undefined consequences because the **[[CL:​Special Operators:​block]]** //​[[CL:​Glossary:​form]]//​ exits normally before the **[[CL:​Macros:​return-from]]** //​[[CL:​Glossary:​form]]//​ is attempted.
 +
 +<​blockquote>​
 +([[CL:​Functions:​funcall]] ([[CL:​Special Operators:​block]] [[CL:​Constant Variables:​nil]] #'​([[CL:​Symbols:​lambda]] () (return-from [[CL:​Constant Variables:​nil]]))))
 +<​e>​ERROR:​ attempt to RETURN-FROM a block that no longer exists.</​e>​
 +</​blockquote>​
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +None.
 +
 +====See Also====
 +  * **[[CL:​Special Operators:​block|Special Operator BLOCK]]**
 +  * **[[CL:​Macros:​return|Macro RETURN]]**
 +  * {\secref\Evaluation}
 +
 +====Notes====
 +None.
 +
 +\issue{EXIT-EXTENT:​MINIMAL}