Re: Multi-assign

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

I have viewed this thread with dismay.

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

Why?

What's wrong with having a function return multiple values?

bill said...

Everyone seems to see only the positive (multi-assignment is good!). Yes it is useful (marginally).

What are the negative effects?

bill said...

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.)

Agreed. This is not the creation-of-sequence operator. This is in fact the inverse, it is desequencing.

bill said...

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).

Desequencing implies that the return type has to be a sequence (before the sequence can be desequenced) and to have a different type is to cause an error.

bill said...

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

Well, you have a return value that is a sequence s that is desequenced such that a is assigned to s[1] and c is assigned to s[3] and s[2] is ignored.

bill said...

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.

So that symbol has at least two meanings. What of it?

I see these two technical meanings as very closely related. In both usages, the user is telling the language that the user does not care about the value.

bill said...
  {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 answer:

  {a,b,c} = {1,2,3}   -- a:=1, b:=2, c:=3 
  -- conceptually shorthand for 
  sequence temp_s = {1,2,3} 
  a = s[1] 
  b = s[2] 
  c = s[3] 
  delete temp_s 
  {1,2,3} = {a,b,c}   -- an error 
bill said...

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.

I'm not clear on what you mean here.

It is technically possible to distinguish between the two. I know this because the code to do so has already been written and tested. The interpreter/translator/parser is able to do this.

Perhaps you mean that you think the concept is too confusing for a user?

bill said...

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.

I don't care much one way or the other on what symbols or characters are used, but changing that would not change the fundamental nature of desequencing.

A function would still return a sequence, and the operators would still desequence it.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu