Re: foreach

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

And to lump something else in there, what about [optionally] specifying a type for the 'each'?

foreach integer c in my_string do 
    -- ... 
end foreach 

What is the semantics behind that?

Does it mean that it only selects the integers contained in my_string and ignores non-integers? Or does it crash if a non-integer is found?

I'd mean for it to crash with a type check error on non-integers. So it would be (at least in the 'simple' version) equivalent to:

for i = 1 to length(my_string) do 
    integer c = my_string[i] 
    -- ... 
end for 

Using a known integer variable can dramatically speed up both interpreted and translated code. In the case of the translator, it would also be an additional hint about the type (even if it were atom or sequence) that could be used for other optimizations. I'd treat anything not specified as an object, of course.

Matt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu