Re: case and foreach

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

Jason Gade wrote:
> 
> I've thought about foreach and I don't really think that it needs to be added
> to the
> language because it can be done with a function or procedure.
> 
> foreach(list_of_stuff, routine_id(some_action))
> 
> or
> 
> list_of_stuff = foreach(list_of_stuff, routine_id(some_action)) --Prefer pass
> by reference
> or optimization of this case

Thing is, this puts the loop and the code inside the loop in different places
making the code harder to read. Imagine how eu code would be if the for loop
was implemented the same way, as a function or procedure! Spaghetti-code.
 
> But it is something that could be helped by having pass by reference and an
> eval()
> function.
> 
> One problem with a built-in foreach -- does it only iterate the top level of a
> sequence
> or does it dig down through sub sequences?  I think that is one reason to
> leave it
> as a procedure or function.

With the same logic, why should the find() function exist? It only iterates
the top level of a sequence, yet it's very useful and your code can get much
faster if you structure your sequences so you can use it.
 
Regards, Alexander Toresson

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

Search



Quick Links

User menu

Not signed in.

Misc Menu