REBOL Technologies

Lots of feedback on FORALL [Updated]

Carl Sassenrath, CTO
REBOL Technologies
1-Jun-2005 15:45 GMT

Article #0170
Main page || Index || Prior Article [0169] || Next Article [0171] || Post Comments || Send feedback

We have received quite a bit of feedback from users regarding my prior article about the FORALL and FORSKIP functions. Opinions were evenly split between the "change it" and "don't change it" camps.

To help settle this issue, we've created a new test build of REBOL (View 1.2.116) that includes the modified versions of the FORALL and FORSKIP functions. You should try these out very soon (today if possible), and let us know what you think. If we do not hear a strong objection, these will become the new functions.

Here is a short example to help clarify:

items: system/locale/days
forall items [print items/1]
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday

The items block is now reset to its original position:

probe items
["Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"]

But, if you BREAK during the loop, the block will stay at the break position:

forall items [if find items/1 "Fri" [break]]
probe items
["Friday" "Saturday" "Sunday"]

And finally, if you begin the loop at an offset position (not the head), that's what will be reset to after the operation:

forall items [print items/1]
Friday
Saturday
Sunday
probe items
["Friday" "Saturday" "Sunday"]

There is just one other important case:

result: forall items [
    if find items/1 "Fri" [break/return true]
]
if result [print "Found it"]

Here the return value of the FORALL function indicates if the item was found or if the loop completed without it being found.

Important note:

In the example above, if no BREAK occurs, FORALL will return the result of the block. If BREAK/return, the value is that provided to the BREAK.

I would like to thank Gregg Iriwn and Ladislav Mecir for their help in developing, building, and testing this solution.

Post Comments

Updated 1-Mar-2024   -   Copyright Carl Sassenrath   -   WWW.REBOL.COM   -   Edit   -   Blogger Source Code