[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [plt-scheme] Return from do
Nicolas Neuss wrote:
> pocm@rnl.ist.utl.pt (Paulo J. Matos) writes:
>
>> Hi all,
>>
>> How can I get out of do before iteration ends?
>> In CL I use return and return-from, how can I do it in
>> PLT Scheme?
Use let/ec if you only need to escape.
This example multiplies the numbers in a list.
There a premature exit if, the product becoms 0.
> (let/ec return
(do ([numbers (list 1 2 3 0 7 9) (cdr numbers)]
[factor 1 (car numbers)]
[product 1 (* product factor)])
((or (= product 0) (empty? numbers))
(return product))
(display factor) (newline)))
This evaluates to 0. During the evaluation
it prints 1,1,2,3 and 0.
--
Jens Axel Søgaard