Re: Multi-assign

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

I have viewed this thread with dismay.

Everyone seems to see only the positive (multi-assignment is good!). Yes it is useful (marginally). It provides a simple swap {a, b} = {b, a} and it allows the dreadful {?, x} = value(Y).

Consider:

integer a, b, c 
 
{a,b,c} = f(x)    -- 1 

A function (presumably) returns one value (sequence or atom).

If you are able to recover a, b & c then the {} are not acting as sequence forming operators in (1). (Otherwise: there would be a complaint about them being used before being initialised.)

The assumption is that the function will return values appropiate to the types of the LHS. What should those types be? The library functions often return different types (eg gets() returns -1 or a sequence).

{a,?,c} cannot be a sequence a slice [1..2] - what is its value?, its length?

f(x, ?, y): by the reasoning of {a, ?, c} the ? means 'disregard this value' not 'use the default'.

Disregard this value makes no sense applied to a function parameter.

Confusion between {a,b,c} = {d,e,f} as L-value <- R-value and an expression (pure R-value).

  {a,b,c} = {1,2,3}   -- either a:=1, b:=2, c:=3 or {a=1,b=2,c=3} 
  {1,2,3} = {a,b,c}   -- either an error or {a=1,b=2,c=3} 

The problem is not that you can't make this work. The problem is that syntactically they are identical. Therefore you cannot distinguish between an erroneous expression and a (correct) assignment and vice versa.

Instead of using {a,b,c} why not use something like < a, b,c > or | a, b, c | for multi-assign? That way it is clear this is not a sequence, but a list of some kind.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu