[REBOL] Re: Rolling your own ideal looper: does Repeat still have a bug? Re:(2)
From: g:santilli:tiscalinet:it at: 29-Aug-2000 19:17
Hello [galtbarber--MailAndNews--com]!
On 28-Ago-00, you wrote:
g> By the way, do you know how Rebol itself
g> does foreach internally? Do they use a function
g> like you did, or is it done some other way?
Probably they're doing something like:
foreach: func [
"Evaluates a block for each value(s) in a series."
'word [get-word! word! block!] {Word or block of words to set each time (will be local)}
data [series!] "The series to traverse"
body [block!] "Block to evaluate each time"
/local amount
] [
if get-word? word [word: get word]
use compose [(word) this-context] [ ; of course the native code
; doesn't need the extra word
bind body 'this-context
amount: either block? word [length? word] [1]
while [not tail? data] [
set word data
do body
data: skip data amount
]
]
]
Obviously the native code might look a lot different. ;-)
Also, since they're probably not calling the WHILE native, there
will be some magic code to make BREAK etc. work as expected.
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/