Re: foreach
- Posted by unkmar Jul 24, 2008
- 1123 views
I like the ability to modify the variable:
s = {1,2,3} foreach x in s do x *= 2 end foreach -- s is now {2, 4, 6}
I think a simple foreach added to 4.0 would be a good thing. We can add in parameters in 4.1 such as reversed and multiple item iteration. The same with the above variable modification. As for the changing list size, I would make it act like a for, i.e. from x to y, thus foreach is equivilent to:
s = {1, 2, 3} foreach x in s do ? x end foreach -- Same as: for i = 1 to length(s) do x = s[i] ? x end for
To add that would be pretty simple, effective for 90% of all uses and does not mean we cannot add on the other fancies in 4.1, yet would be easy to implement, would reseve the keyword in 4.0, add greater functionality to Euphoria brining it closer to syntax capabilities of our competitors and at what cost? I do not see any except a bit of time to implement.
Jeremy
This view fits very well within my expectations of an intial version. I agree that additional features should only be added after the 4.0 release. Allowing everyone plenty of time to hash out their opinions on the positives and negatives of each nuance.
Another optional format is:
--parentheses are optional. Just part of my coding style. -- I don't like this format foreach (list as item) do ? item end foreach --I prefer this foreach (item in list) do ? item end foreach