Pascal Costanza <··@p-cos.net>:
> (tagbody
> :start ...
> (go :start) ; similar to continue
> (go :end) ; will never get reached
> :end)
>
> However, this is very low-level, and it is probably better to hide this
> with a macro.
And the macro is already in CL, it's called BLOCK.
(dolist ...
(block dolist-body
...
(when something
(return-from dolist-body)
...)))
But I prefer to just conditionalise the rest of the loop:
(dolist ...
...
(unless something
...))
> Another route to go is to use recursion:
>
> (labels ((for (... args ...)
> (for ... args ...)
> some-value ; will never get reached
> ))
> (for ... initial-values ...))
You should note that this is not blessed by ANSI Common Lisp -- the
'spec does not mandate removal of tail calls. If you adopt this style
(which I recommend), you'll be okay at least in CMUCL, SBCL and CLISP.
Juliusz
Juliusz Chroboczek wrote:
> Pascal Costanza <··@p-cos.net>:
>
>>Another route to go is to use recursion:
>>
>>(labels ((for (... args ...)
>> (for ... args ...)
>> some-value ; will never get reached
>> ))
>> (for ... initial-values ...))
>
>
> You should note that this is not blessed by ANSI Common Lisp -- the
> 'spec does not mandate removal of tail calls. If you adopt this style
> (which I recommend), you'll be okay at least in CMUCL, SBCL and CLISP.
a) Depends on how deep your recursion goes. ;)
b) Also Allegro supports removal of tail calls for speed > 1, debug < 2;
LispWorks for debug < 3; MCL and OpenMCL do this by befault. In CMU and
SBCL it can be switched off by setting debug > 2.
At least that's what the documentations claim.
Pascal
--
OOPSLA'05 tutorial on generic functions & the CLOS Metaobject Protocol
++++ see http://p-cos.net/oopsla05-tutorial.html for more details ++++