Re: case and foreach

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

cklester wrote:

> Since Euphoria doesn't have objects, I don't see how this would be more
> useful than what's already available.
> 
> for each x in 1 to 50 do
>     ?x
> end for
> 
> Although it would work for iterating through sequences...
> 
> sequence s
> s = {1,2,3,4,5}
> for each x in s do
>     ?x
> end for
> 
> Do any of the OOP libraries out there use this construct to loop through
> objects in a class/library/whatever?
> 

Actually, first off, Euphoria does have Objects, just depends on your
point of view of what an Object is.  If you step back, and take a look at
Euphoria, as it stands, you'll start to notice, that Objects are actually
Variables, Procedures, and Functions, and classes become the actual
filename.  The only thing that remains laxed in Euphoria, is the fact that
Dynamic Includes will not become a possibility, or dynamic creation of
objects at the Language level will happen.

As for your question, yes, SOOP uses the for method mentioned in the second
half to manipulate the Variable Table, by implementing the DataType System.

It actually becomes:
for x = 1 to length(ObjectMembers[ix]) do
    ObjectMembers[ix][x] = DataType_InitVar(soop_MemberType(class_ix,x))
end for

Personally, I like the foreach system, but I'd rather prefer it as a
builtin, so that futher enhancements can happen, such as:
foreach s in x as y do
    printf(1,"%s is %s",{y,s})
end foreach
Where y becomes a refrence Identifier, or in the lack of refrence identifiers
in euphoria, the numeric subscript of the item.

As for the top level sequence, or scan through sub-sequences, it should be
fairly ovious, that it should only deal with the top level sequence.  Any
sub-sequencing that needs to be done, should be included as a new
foreach statement block.  Such as:
sequence x
x = {1,{2,3,4},5,{6}}

foreach s in x as y do
   if sequence(s) then
      foreach z in s as d do
        printf(1,"%d:%d Value: %d",{y,d,z})
      end foreach
   else
      printf(1,"%d Value: %d",{y,s})
   end if
end foreach


Just my thoughts on it.  As for the case deal, yes, this would indeed
clean up the if/elsif/elsif/elsif/end if block, where you could have about
half a million cases to a simple if switch.  However, it's more likely that
you'll get the foreach, and case implemented either into a Pre-Proccessor,
or into the PD Source, before it'll be seriously looked at, if at all by
Rob.  Not trying to be a downer, just pointing that out.

Also, one final note to make, since I've seen this alot....  Some think that
if you use the PD Source Code, to make your own flavor of Euphoria, that your
restricted to Euphoria's "laws" when implementing your features into the
interpreter, since it uses Euphoria's 2.5 engine.  However, this is not the
case.

Yes, your Interpreter will be running off the 2.5 engine, for the
interpreter's code space.  The application developed under your interpreter,
will be following the rules you layed out in your modified interpreter, not
the 2.5 engine.  This means, you can create an entirely new language, and
as long as the code is correct in the source for YOUR interpreter, to follow
the 2.5 engine's laws, then it will work.

Just thought I'd make that remark, cause it seems to be missed.

Mario Steele
http://enchantedblade.trilake.net
Attaining World Dominiation, one byte at a time...

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

Search



Quick Links

User menu

Not signed in.

Misc Menu