Re: [Phix] Language Feature Request: For Each

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...

Why "for i"? (It seems redundant.)

Sigh. I already explained this in detail above. Let me try again:
There has to be an index (how else do you suggest it iterates down a sequence?),
so I may as well force you to give it a name, and as a bonus show it in the ex.err,
plus it avoids the almost inevitable "so how do I modify all_keys then?" questions.
I'll take another look at hiding it/making it "optional" when/if ever implemented.

euphoric said...

Javascript's forEach() is definitely interesting, but is a method on a class (it seems), so not analogous to Phix's version (it seems).

JavaScript's Array.forEach() is 96% slower than a plain for loop and requires an iterator which is inherently tied to the defining scope, plus there is no String.forEach() method.
(Note that p2js does not use JavaScript Objects at all, since despite their {} syntax they are far closer to dictionaries than Phix sequences, for which it uses [faster] Arrays.)
The Phix method would just be a shorthand anyway, and hence p2js would just slap out a longhand version, should I ever get round to it.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu