Re: Plans for Euphoria

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

CChris wrote:
> 
(snip)
> 
> foreach is desperately needed. However, I see a problem with the way you
> explain
> it.
> For this to be useful, you need both an index, because you may have decisions
> 
> to make on the index, and the element value. So perhaps something like
> }}}
<eucode>
> foreach char [at idx [from start_index ][to somewhere ][by some_step]] in
> string do
> -- code where idx incrementing and char=string[idx] always
> end foreach
> </eucode>
{{{

> 
> You may forget idx if you don't need it. If some_step is negative, I'd expect
>  idx to start at length(string). Both char and idx would look like current 
> for loop indexes I bet (undeclared, local to the for loop).

You don't need all of that actually since you can just do:

foreach char in string[start_index..somewhere] do
    ...
end foreach

and to go backwards from somewhere to start_index:

foreach char in reverse(string[start_index..somewhere]) do
    ...
end foreach

Having a step value might be useful though.

> Also, do you plan to care for the case where string gets modified in 
> structure during the process?

I'm going to say probably not just like we can't change a sequence while
assigning to a slice of it.


> As for perform, why not just write:
> }}}
<eucode>
> constant my_computed_constant(perhaps with parameters)
> -- some code here
> end constant
> </eucode>
{{{

> 
> This would make my_computed_constant a constant, initialised the first time
> 
> the routine code inside the block is run. Isn't that simpler?

Simpler perhaps, but harder to read I'd say since it looks just like a function
or procedure definition. Also, perform could be used for any variable/value not
just constants.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu