On May 30, 9:31 pm, ···········@gmail.com" <··········@gmail.com>
wrote:
> Is there any function to break from a loop as we have break in C or C+
> +.
If you are talking about the loop macro there's a (return) clause
see http://www.gigamonkeys.com/book/loop-for-black-belts.html
-- Mac
Can we use the return macro for exiting from the while loops also??
Regards,
Gokul
mac wrote:
> On May 30, 9:31 pm, ···········@gmail.com" <··········@gmail.com>
> wrote:
> > Is there any function to break from a loop as we have break in C or C+
> > +.
>
> If you are talking about the loop macro there's a (return) clause
>
> see http://www.gigamonkeys.com/book/loop-for-black-belts.html
>
> -- Mac
On May 30, 10:06 pm, ···········@gmail.com" <··········@gmail.com>
wrote:
> Can we use the return macro for exiting from the while loops also??
There's no built-in while loop in cl, but you can build one with
macro.
Here's an example with the loop macro
CL > (loop for i from 1
while (< i 10)
if (= i 5) do (return)
else do (princ i))
1234
NIL
On 30 May 2007 22:06:28 -0700, ···········@gmail.com" <··········@gmail.com> said:
| Can we use the return macro for exiting from the while loops also??
You are not asking about Elisp's (Emacs Lisp's) `while' special
form, are you?
Other constructs for iteration that Common Lisp has include (but are
not limited to) DO, DOLIST, and DOTIMES, and RETURN can be used to
exit from any of them.
---Vassil.
--
The truly good code is the obviously correct code.
Yes. I am working in elisp only.
Vassil Nikolov wrote:
> On 30 May 2007 22:06:28 -0700, ···········@gmail.com" <··········@gmail.com> said:
>
> | Can we use the return macro for exiting from the while loops also??
>
> You are not asking about Elisp's (Emacs Lisp's) `while' special
> form, are you?
>
> Other constructs for iteration that Common Lisp has include (but are
> not limited to) DO, DOLIST, and DOTIMES, and RETURN can be used to
> exit from any of them.
>
> ---Vassil.
>
>
> --
> The truly good code is the obviously correct code.
···········@gmail.com" <··········@gmail.com> writes:
> Yes. I am working in elisp only.
>
>
> Vassil Nikolov wrote:
>> On 30 May 2007 22:06:28 -0700, ···········@gmail.com" <··········@gmail.com> said:
>>
>> | Can we use the return macro for exiting from the while loops also??
>>
>> You are not asking about Elisp's (Emacs Lisp's) `while' special
>> form, are you?
>>
>> Other constructs for iteration that Common Lisp has include (but are
>> not limited to) DO, DOLIST, and DOTIMES, and RETURN can be used to
>> exit from any of them.
The it'd be better to ask in news:comp.emacs or news:gnu.emacs.help
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
----------> http://www.netmeister.org/news/learn2quote.html <-----------
---> http://homepage.ntlworld.com/g.mccaughan/g/remarks/uquote.html <---
__Pascal Bourguignon__ http://www.informatimago.com/
Hi,
Pascal Bourguignon <···@informatimago.com> writes:
> The it'd be better to ask in news:comp.emacs or news:gnu.emacs.help
Nevertheless a solution may be valuable.
There is an example in (info "(elisp)Nonlocal Exits")
Or for the command line:
info elisp "Control Structures" "Nonlocal Exits"
Regards
stefan
--
Stefan Kamphausen --- http://www.skamphausen.de
a blessed +42 regexp of confusion (weapon in hand)
You hit. The format string crumbles and turns to dust.
On May 31, 7:58 am, mac <········@gmail.com> wrote:
> On May 30, 9:31 pm, ···········@gmail.com" <··········@gmail.com>
> wrote:
>
> > Is there any function to break from a loop as we have break in C or C+
> > +.
>
> If you are talking about the loop macro there's a (return) clause
Actually this is confusing several things into one. There is CL:RETURN
(and CL:RETURN-FROM)
and there is a RETURN clause in LOOP.
On 2007-05-31 00:31:04 -0400, ···········@gmail.com"
<··········@gmail.com> said:
> Is there any function to break from a loop as we have break in C or C+
> +.
CL-USER 22 > (loop named foo
for bar = 0 then (random 100)
do (if (> bar 76) (return-from foo bar) (print bar)))
0
72
25
16
69
63
9
63
79
CL-USER 23 > (loop for bar = 0 then (random 100)
do (print bar)
when (> bar 76)
return (values))
0
24
11
21
47
60
53
21
78
CL-USER 24 > (loop for bar = 0 then (random 100)
do (print bar)
thereis (> bar 76))
0
44
97
T
CL-USER 25 > (catch 'baz
(loop for bar = 0 then (random 100)
do (print bar)
(if (> bar 76)
(throw 'baz bar))))
0
73
71
29
36
20
34
0
93
93
CL-USER 26 > (tagbody
(loop for bar = 0 then (random 100)
do (print bar)
(if (> bar 76)
(go baz)))
baz)
0
48
17
91
NIL
On Thu, 31 May 2007 01:33:21 -0400, Raffael Cavallaro
<················@pas-d'espam-s'il-vous-plait-mac.com> tried to confuse everyone
with this message:
>On 2007-05-31 00:31:04 -0400, ···········@gmail.com"
><··········@gmail.com> said:
>
>> Is there any function to break from a loop as we have break in C or C+
>> +.
>
<snip>
Also there is loop-finish macro, which is often preferable to above-mentioned
methods.
--
|Don't believe this - you're not worthless ,gr---------.ru
|It's us against millions and we can't take them all... | ue il |
|But we can take them on! | @ma |
| (A Wilhelm Scream - The Rip) |______________|
On 2007-05-31 07:55:47 -0400, ····@mail.ru (Timofei Shatrov) said:
> Also there is loop-finish macro, which is often preferable to above-mentioned
> methods.
Yes, but one should be aware that loop-finish is unlike break in that
loop-finish causes execution to continue with the loop epilogue - the
parts after finally or the automatic return of any accumulated values -
while break in c and the methods shown above in lisp will cause control
flow to exit the loop entirely - sbcl for example will delete the
epilogue in such cases as unreachable code.
For example, this is probably not what one wants:
CL-USER> (loop named foo
for i = 0 then (random 100)
collect i ;;; you'll never see this accumulated list
when (> i 76) do (return-from foo i))
; in: LAMBDA NIL
; (RETURN-FROM FOO (SB-LOOP::LOOP-COLLECT-ANSWER #:LOOP-LIST-HEAD-1775))
;
; note: deleting unreachable code
;
; compilation unit finished
; printed 1 note
92
but this is:
CL-USER> (loop for i = 0 then (random 100)
collect i
when (> i 76) do (loop-finish))
(0 47 32 52 95)
and this could be too:
CL-USER> (loop named foo
for i = (random 100)
collect i
when (= i 91)
do (return-from foo 'exceptional-number-encountered)
when (< i 10)
do (loop-finish))
(65 54 37 50 38 93 12 99 94 83 95 77 39 62 82 51 62 88 2)
CL-USER> (loop named foo
for i = (random 100)
collect i
when (= i 91)
do (return-from foo 'exceptional-number-encountered)
when (< i 10)
do (loop-finish))
EXCEPTIONAL-NUMBER-ENCOUNTERED
loop-finish is more like a 'go' to a label placed at the start of the
loop epilogue rather than a simple break, so one should use loop-finish
when one *always* wants the loop epilogue to execute, and one should
use one of the other techniques when one wants exceptional situations
to terminate the loop a-la c's break - without executing any loop
epilogue.