Lots of feedback on FORALL [Updated]
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.
I would like to thank Gregg Iriwn and Ladislav Mecir for their help in developing, building, and testing this solution.
Updated 22-May-2023 - Copyright Carl Sassenrath - WWW.REBOL.COM - Edit - Blogger Source Code