1. Re: 3.0 feature request: foreach
- Posted by ags <eu at 531pi.co.nz> Jul 13, 2005
- 417 views
Derek Parnell wrote: > > All I can add is that for those languages that have a foreach construct, the > clarity > of code is enhanced when compared to alternative constructs. I strongly agree with foreach unless it is too difficult to implement in the interpreter (ie would compromise the efficiency.) I tire quickly of writing 'for i = 1 to length(...)'. I don't see the 'foreach i in s' system being too much of a problem. Either that or make sequence 's' act like the atom 'length(s)' in an atom context. (That's a joke--there's a much better language for that sort of thing :) > > Vincent wrote: > > It wouldnt be worth Robert's effort to implement "continue" either, > > it just isn't useful enough. > > And how was the "usefulness" value determined? I have many instances in which > my Eu > code can be clarified by this idiom. If "exit" was deemed useful then so would > "next" > or "continue", especially once people start seeing the freedom of expression > and clarity > is gives to coders. I vote 'next' rather than 'continue' (if at all). 'next' has a more intuitive meaning. ie 'next iteration', whereas 'continue' could mean 'finish the for loop and continue'. Nobody (?) is going to confuse 'next' for 'next bit of code after the for loop'. 'next' is short too. I just wrote another paragraph explaining why 'next' (w.h.y.) is so important but became unconvinced myself What keeps coming back to me is how quickly I learned Euphoria (after knowing C/Perl/PHP etc 'basically C syntax languages') because of the lack of those keywords. I like the 'end this', 'end that' paradigm which makes 'end' a keyword and lessens the total keywords (imagine 'endif', 'endfunction', 'endprocedure' :) Who knows, Euphoria might just fit in to a mind mapping sweet-spot without the extra keywords. I think there are bigger things to worry about with the language than the basic syntax, but in order of preference, my (registered user) opinion is in the priority: (1) - next (or continue) (2) - foreach automatic-atom in sequence (3) - foreach automatic-object in sequence by (some definition) eg 'by -1' = each object, 'by 0' = as atoms, >= 1 sequences of that length (4) - keeping the basic syntax as uncluttered as it already is and extending the syntax or functionality solely by include files or a mechanism (such as the existing type mechanism) The reason for suggesting (3) would be to satisfy those who want 'foreach', and lifting Euphoria even higher in GL'ness. I've just realised that (2) is probably unworkable. How do you know the sequence contains only atoms, and why cater to only that situation? Gary