Re: Multi-assign

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

For 4.1, I started working on multiple assignment. Basically, it would look like this:

I've documenting what I've done. It currently looks like this:

Multiple Assignment

Special sequence notation on the left hand side of an assignment can be made to assign to multiple variables with a single statement. This can be useful for using functions that return multiple values in a sequence, such as value.

atom success, val 
 
{ success, val } = value( "100" ) 
 
-- success = GET_SUCCESS 
-- val     = 100 

It is also possible to ignore some of the values in the right hand side. Any elements beyond the number supplied on the left hand side are ignored. Other values can also be ignored by using a dollar sign ('$') instead of a variable name:

{ $, val } = value( "100" ) 

Variables may only appear once on the left hand side, however, they may appear on both the left and right hand side. For instance, to swap the values of two variables:

{ a, b } = { b, a } 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu