Re: Multiple assignment?

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

I'm still finding my way around Eu, and keep getting confused by possibilities in other languages.

Right now, I am looking for a tidy way to pull elements from a sequence into separate variables, something like

-- object a, b, c 
-- sequence s = { 111, 222, 333 } 
-- a , b, c = s 
-- 
-- yielding a=>111, b=>222, c=>333 

Is there any idiom for doing something like that in Eu?

With the next version of Euphoria (v4.1) you will be able to do multiple assignments. For example ...

function f( sequence x) 
 
   return x * x + 2 * x + length(x) 
    
end function 
 
object a,b,c 
 
{a,b,c} = {1,2,3}  -- Assign literal values to each of 'a', 'b', and 'c' 
 
? {a,b,c} 
 
{c,?,b} = f({a,b,c}) -- Assign function return elements.  
                     -- But note the '?' means skip respective element. 
? {a,b,c} 
 
{a,b} = {b,a} -- swap two items. 
 
? {a,b,c} 
 
{a} = f({a,b,c}) -- Also handles unmatched number of elements  
 
? {a,b,c} 
 

This will display ...

{1,2,3} 
{1,18,6} 
{18,1,6} 
{363,1,6} 

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

Search



Quick Links

User menu

Not signed in.

Misc Menu