A surprise from REPEAT
[1/4] from: larry:ecotope at: 1-Aug-2001 19:56
Hi all, I just got a surprise from the REPEAT function. We all use it in the standard form of
>> blk: [x y z]
== [x y z]
>> repeat j length? blk [print j]
1 2 3 where the second argument to REPEAT is the number of repetitions, and j iterates from 1 to that number. Well I inadvertently left LENGTH? out of my statement and got this instead
>> repeat j blk [print j]
x y z So REPEAT has the same capability as FOREACH to access each item of a series. I don't recall seeing this documented anywhere, so I thought I would mention it here. It sure surprised me!! -Larry
[2/4] from: fsievert:uos at: 2-Aug-2001 9:06
The web page referred to in this message is no longer accessible.
Even more: 'repeat is the better choice at the moment, because 'foreach uses to crash sometimes. Look at http://proton.cl-ki.uni-osnabrueck.de/REBOL/bug-test.r for more infomations. (USE AT YOUR OWN RISK, IT WILL CRASH REBOL) 'test1 and 'test2 are doing exactly the same, but one with 'foreach and one with 'repeat. Frank On Wed, 1 Aug 2001, Larry Palmiter wrote:
[3/4] from: g::santilli::tiscalinet::it at: 2-Aug-2001 19:02
Hello Larry! On 02-Ago-01, you wrote: LP> I don't recall seeing this documented anywhere, so I thought LP> I would mention it here. It sure surprised me!!
>> help repeat
USAGE: REPEAT 'word value body DESCRIPTION: Evaluates a block a number of times or over a series. <------------- REPEAT is a native value. ARGUMENTS: word -- Word to set each time (Type: word) value -- Maximum number or series to traverse (Type: integer series) body -- Block to evaluate each time (Type: block) (If you can call this documentation... :) The difference between REPEAT and FOREACH is that the latter allows using multiple words. Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[4/4] from: lmecir:mbox:vol:cz at: 3-Aug-2001 9:19
----- Original Message ----- From: Gabriele Santilli <[g--santilli--tiscalinet--it]> To: <[rebol-list--rebol--com]> Sent: Thursday, August 02, 2001 7:02 PM Subject: [REBOL] Re: A surprise from REPEAT ...
> The difference between REPEAT and FOREACH is that the latter > allows using multiple words. > > Regards, > Gabriele.
...and the former modifies its BODY argument