FOREACH Series Reference Variable

Carl Sassenrath, CTO
REBOL Technologies
2-May-2006 16:33 GMT

Article #0015
Main page || Index || Prior Article [0014] || Next Article [0016] || 15 Comments || Send feedback

Something I've always wanted in foreach: the ability to access the series, not just its values. In otherwords, kind of a blend of forall and foreach.

One way to do this is to allow the foreach word block to include some kind of notation that a word is meant to refer to the series, not a value of the series. For example:

foreach [name count:] user-data [
    change count length? name

This example shows the power of the method. Here the count variable refers to the series at that index, so the example is modifying the actual series block here. The set-word notation is consistent with that used in the parse dialect for a similar purpose.

You can also use such a word to get you the index position without needing to increment a separate variable within your foreach loop.


Updated 22-Jun-2024 - Edit - Copyright REBOL Technologies -