[REBOL] Re: What does "loop" return?
From: gregg::pointillistic::com at: 4-Apr-2009 13:54
Hi Valeri,
Welcome to REBOL!
бл> My question is: what does "loop" ("foreach" and so on) return? Namely:
...
бл> (seems like last evaluated value).
Correct.
бл> So there are some questions:
бл> - is that desirable ?
What else would you suggest they return?
бл> - what is the sense of such behaviour ?
Consistency, and the ability to use the result.
бл> - why only second case is described in REBOL/Core doc ? (and for REBOL
бл> 3 too)
I'm not sure what you mean here.
бл> - if I am wrong and in first case "loop" returns value too then
бл> how this value (block [3 3]) is calculated ?
>> loop 2 [append [] 3]
== [3 3]
>> append append [] 3 3
== [3 3]
>> r: append [] 3
== [3]
>> append r 3
== [3 3]
In general, think about what REBOL returns when a block is evaluated.
What are you doing when you use LOOP, or FUNC? What does a function
return (assuming you don't use EXIT or RETURN in the body)?
REBOL is great fun, but it is also very different from other
languages. Don't be discouraged by things that seem odd, and feel free
to post any questions, even if they seem simple.
-- Gregg