RE: Possible feature for new Euphoria-version

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

> 
> With my way (or something like it, Matt's seems to flip it around?), you 
> 
> can pick an arbitrary number of elements at arbitrary depths without 
> needed to anything about the shape & size at compile time.  I use 
> routines that do just what I'm suggesting quite often now, and building 
> the "subscriting sequence" is not particularly hard.
> 
> Your way is better if you know what you want before-hand, but the point 
> of using a sequence for subscripts is that you don't know what you want. 
> 
>  But since [a,b,c] is fundamentally different from [{a,b,c}], why can't 
> we do it all -- your way and my way (or Matt's way)?
> 
> New, "list" shorthand, plus the ability to use a sequence that can pick 
> arbitrary elements from anywhere in the sequence at any depth.  I want 
> it all!
> 


Another thought.  In my own work, the main purpose of flexible 
subscripting like this is usually for some sort of conditional 
filtering/extraction from sequences.  With nested sequences, usually I'm 
navigating with a recursive "sequence diver" function, and often 
extracting from one sequence based on what is what in another sequence 
(of identical structure).

Which leads to a 4th way to do subscripting by sequence -- via a truth 
vector.  For instance:

s = {1,3,5,7,9,2,4,6,8,10}

s = s[s < 5]

-- which is same as:

s = s[{1,1,1,0,0,1,1,0,0,0}]

-- Now s = {1,3,2,4}


And this could work for nested sequences as well -- the subscripting 
sequence is of indentical structure to the sequence being subscripted.  
Could be a bit much for very large nested sequences though.

BTW Rob, let's get that conditional operator for next version too.  I'd 
love to do this:

s = {1,2,3,4,5,6,7,8,9,10}


s = (s < 5) iftrue (s*2):(s*4)

-- now s = {2,4,6,8,10,24,28,32,36,40}

instead of:

for i = 1 to length(s) do
  if s[i] < 5 then
    s[i] *= 2
  else
    s[i] *= 4
  end if
end for

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

Search



Quick Links

User menu

Not signed in.

Misc Menu