Re: Multi-assign

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

Some interesting possibilities with LHS symbolic sequences:

  • Initializing several variables with the same value:
{a,b,c} = 0

When the RHS is an atom, we might be able to get away with this, but once the RHS is a sequence, we strike ambiguities.

Consider ...

{a,b,c} = 1       -- Assign 1 to a, b, and c 
{a,b,c} = {d,e,f} -- Assign {d,e,f} to a, b, and c or 
                  -- assign d to a, e to b, and f to c? 

IMHO, one of the intentions of multi-assign is to simplify the access to the elements of a returned sequence of a function. Then:

{a,b,c} = {d,e,f} -- assign d to a, e to b, and f to c

To satisfy the other case:

{a,b,c} = { {d,e,f} , {d,e,f} , {d,e,f} } 

- Fernando

Yes, but the problem I see is the inconsistency that might happen.

If {a,b,c} = 1 means assign to each symbol on the LHS the value on the RHS, then why does {a,b,c} = {1,2,3} mean something different?

My first thought was: because this is the Euphoric way. Comparing:

s += 1

with:

s += {a,b,c}

In the first case, each element of s is incremented. In the second case, first element of s is added by a, second element of s is added by b, ... and NOT the first element of s is added by {a,b,c}, ... But, the assignment operator '=' does not work as the assignment WITH operator (+=, *= , etc). We cannot assign an atom to a sequence. Thus, I think you're right: there would be an inconsistency in that form of initialization similar with the inconsistency in assignment operator with assignment with operator.

DerekParnell said...

It looks the same; a list of symbols on the LHS and a single value on the RHS ( a single sequence).

Or more to the point ...

{a,b,c} = func() 

Would operate differently depending on whether func() returned an atom or a sequence.

Yes, the assignment would operate differently depending on the type: atom or sequence.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu