1. Multi-assign

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

{ x, y } = { 1, "foo" } 
 
{ $, x } = value( y ) 

It's really syntactic sugar, but can make some code a lot easier to read. My implementation currently uses dollar signs to ignore values. There's been some concern on the dev list that this might be confusing, so I'd like to get feedback from the wider community.

Does a dollar make sense? Should we use a different symbol? Should we just put extra commas in?

For those interested, the code is currently in the 'multi-assign' branch in the Mercurial repo.

Matt

new topic     » topic index » view message » categorize

2. Re: Multi-assign

mattlewis said...

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

{ x, y } = { 1, "foo" } 
 
{ $, x } = value( y ) 

It's really syntactic sugar, but can make some code a lot easier to read. My implementation currently uses dollar signs to ignore values. There's been some concern on the dev list that this might be confusing, so I'd like to get feedback from the wider community.

Does a dollar make sense? Should we use a different symbol? Should we just put extra commas in?

For those interested, the code is currently in the 'multi-assign' branch in the Mercurial repo.

Matt

I don't really understand what multiple assignment is; but if you use a dollar sign in a sequence could it be confused with the last position of a sequence for example: seq[1..$]

new topic     » goto parent     » topic index » view message » categorize

3. Re: Multi-assign

What if you use an _ (underscore)?

new topic     » goto parent     » topic index » view message » categorize

4. Re: Multi-assign

BRyan said...

I don't really understand what multiple assignment is; but if you use a dollar sign in a sequence could it be confused with the last position of a sequence for example: seq[1..$]

Multiple assignment is a way to take the result of an expression that is a sequence, probably most commonly the return value of a sequence, and assign it in one go, without having to use a temporary variable. So:

-- instead of: 
x = value( something ) 
my_number = x[2] 
 
-- you could do: 
{ $, my_number } = value( something ) 

The confusion was the argument brought up, but I'm honestly not sure how one would confuse this. Also, $ can already be used as a list terminator:

constant 
    A = 1, 
    B = 2, 
    $ 
 
sequence s = { 1, 2, 3, $ } 

So, it's basically a place holder. Personally, I like it better than something like an underscore or a dash or a dot because as a glyph, it's fairly substantial and easy to spot and differentiate from other things.

Matt

new topic     » goto parent     » topic index » view message » categorize

5. Re: Multi-assign

The $ sign might be confusing to newer programers, but I don't really see a problem after getting used to it. The underscore would make sence progamatically, but as BRyan said it would not be very visible. How about the '~', in older programs that could not read long file names they were shortened with the tilde to indicate 'missing' chars. Would that make sence? to indicate missing variables. Just a thought.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Multi-assign

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 message » categorize

7. Re: Multi-assign

This is how I understand multiple-assign so far...

Multiple assignment:

demo Newway Oldway
swap

{a,b} = {b,a}

object temp
temp = a
a = b
b = temp 
mutiple return

{ myfirst_number, mysecond_number} = value(something)

object temp = value( something )
? temp
-- { 100, 200 }
myfirst_number = temp[1]
mysecond_number = temp[2] 

Potential multiple return syntax when used with an omitted variable:

Symbol Sample Thoughts
1 'none'

{ , mysecond_number} = value(something)
too bare, easy to miss, bad for the eyes
2 $

{ $ , mysecond_number} = value(something)
symbol in use as end marker
3 #

{ # , mysecond_number} = value(something)
suggests 'comment' hence blank, bad used as #FF hex number
4 !

{ ! , mysecond_number} = value(something)
suggests 'not' as in `!=` hence blank
5 ~

{ ~ , mysecond_number} = value(something)
used in DOS as 'missing'

Of these choices the $ symbol is the worst choice because:

Prior Use Demo
1 sequence end marker -- length

seq[ 1 .. $ ]
2 enum end marker

enum A, B, C, $
3 list end marker

sequence s = { 1, 2, 3, $ }

Clearly, $ means "end marker" in Euphoria. Using $ for other purposes is OK, but using $ for "other purposes" within a sequence is very bad--an entrenched pattern is being broken.

Any marker, other than $, makes more sense.

Consider extending the marker idea to "missing arguments" in a routine:

foo( 1, 2,, 4) becomes foo(1,2,#,4) 

since "invisible" syntax is hard to use.

_tom

new topic     » goto parent     » topic index » view message » categorize

8. Re: Multi-assign

mattlewis said...

Does a dollar make sense? Should we use a different symbol? Should we just put extra commas in?

I dislike extra commas. They are hard to read, easy to get wrong and can make you look for hours for bad code. What about a - ?

{ -, last } = parse_name("John Doe") 

I know extra commas are used for parameters but I'd like to see that be deprecated and whatever we decide here be used there as well.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

9. Re: Multi-assign

_tom said...

This is how I understand multiple-assign so far...

Yes.

_tom said...

Of these choices the $ symbol is the worst choice because:

...

Clearly, $ means "end marker" in Euphoria. Using $ for other purposes is OK, but using $ for "other purposes" within a sequence is very bad--an entrenched pattern is being broken.

Any marker, other than $, makes more sense.

Well, I still disagree. smile There are currently two uses of $: length shortcut in subscripting, and list terminator. I see adding it here as similar to its list termination duties, and like it in part because it's already used that way.

But it looks like I may be out-voted. Of the other options, I think a tilde '~' is the next best choice.

Matt

new topic     » goto parent     » topic index » view message » categorize

10. Re: Multi-assign

_tom said...

Any marker, other than $, makes more sense.

Consider extending the marker idea to "missing arguments" in a routine:

foo( 1, 2,, 4) becomes foo(1,2,#,4) 

since "invisible" syntax is hard to use.

_tom

I think that using the hash is a bad idea, as it's (imvho) more prone to being the result of a typo than the dollar sign would be.

What if the person meant <eucode> foo( 1, 2, #A, 4) </eucode> but missed the 'a'?

Of course, for a LHS of a multi-assign that's not an issue, since we can't have literal values (such as hexadecimals) in there anyways.

new topic     » goto parent     » topic index » view message » categorize

11. Re: Multi-assign

$ is fine by me (or the underscore) to serve as a placemarker meaning "ignore me."

What about the case where there are not enough RHS items to complete LHS requests? Or vice versa?

{ a } = { 1, 2, 3 } 
 
{ a, b, c } = { 1 } 
new topic     » goto parent     » topic index » view message » categorize

12. Re: Multi-assign

I vote for underscore. In some languages there is the anonymous _ variable, which is used when the value doesn't matter.

new topic     » goto parent     » topic index » view message » categorize

13. Re: Multi-assign

euphoric said...

$ is fine by me (or the underscore) to serve as a placemarker meaning "ignore me."

Insolor said...

I vote for underscore. In some languages there is the anonymous _ variable, which is used when the value doesn't matter.

In euphoria v4, an underscore, by itself is actually a valid variable name.

euphoric said...

What about the case where there are not enough RHS items to complete LHS requests? Or vice versa?

{ a } = { 1, 2, 3 } 
 
{ a, b, c } = { 1 } 

In the first case, 1 is assigned to a, and the rest of the sequence is ignored. In the second case, you get a subscript error.

Matt

new topic     » goto parent     » topic index » view message » categorize

14. Re: Multi-assign

mattlewis said...

In euphoria v4, an underscore, by itself is actually a valid variable name.

Which doesn't make it all that different from other keywords that we have added (like 'label' or 'loop') that were previously common variable names.

Even in 4.0 code, I doubt the underscore is a popular variable/routine name. In fact, I wonder if it has been used at all this way by any code.

new topic     » goto parent     » topic index » view message » categorize

15. Re: Multi-assign

jimcbrown said...
mattlewis said...

In euphoria v4, an underscore, by itself is actually a valid variable name.

Which doesn't make it all that different from other keywords that we have added (like 'label' or 'loop') that were previously common variable names.

Even in 4.0 code, I doubt the underscore is a popular variable/routine name. In fact, I wonder if it has been used at all this way by any code.

It has been used at least in some of the euphoria unit tests. Specifically, t_net_dns.e and and t_socket.e.

Matt

new topic     » goto parent     » topic index » view message » categorize

16. Re: Multi-assign

mattlewis said...

It has been used at least in some of the euphoria unit tests. Specifically, t_net_dns.e and and t_socket.e.

Matt

That shouldbe fairly easy to fix up if necessary.

new topic     » goto parent     » topic index » view message » categorize

17. Re: Multi-assign

jimcbrown said...
mattlewis said...

It has been used at least in some of the euphoria unit tests. Specifically, t_net_dns.e and and t_socket.e.

Matt

That shouldbe fairly easy to fix up if necessary.

Ugh. I'd rather not. I think we'd have to add some special handling in the scanner. I think it's more useful to leave it the way it is.

Matt

new topic     » goto parent     » topic index » view message » categorize

18. Re: Multi-assign

mattlewis said...
jimcbrown said...
mattlewis said...

It has been used at least in some of the euphoria unit tests. Specifically, t_net_dns.e and and t_socket.e.

Matt

That shouldbe fairly easy to fix up if necessary.

Ugh. I'd rather not. I think we'd have to add some special handling in the scanner. I think it's more useful to leave it the way it is.

Matt

Wait, what? Why?

new topic     » goto parent     » topic index » view message » categorize

19. Re: Multi-assign

jimcbrown said...
mattlewis said...
jimcbrown said...
mattlewis said...

It has been used at least in some of the euphoria unit tests. Specifically, t_net_dns.e and and t_socket.e.

Matt

That shouldbe fairly easy to fix up if necessary.

Ugh. I'd rather not. I think we'd have to add some special handling in the scanner. I think it's more useful to leave it the way it is.

Matt

Wait, what? Why?

I'm going from memory, but basically, an underscore is a valid symbol character. We used to say that symbols couldn't start with an underscore, but that restriction was removed at some point during 4.0 development. The naked underscore name is just a variable that starts with an underscore, but has no more characters. Maybe not a big deal, and I'm blowing it out of proportion.

I still like the $. tongue

Matt

new topic     » goto parent     » topic index » view message » categorize

20. Re: Multi-assign

mattlewis said...

I'm going from memory, but basically, an underscore is a valid symbol character. We used to say that symbols couldn't start with an underscore, but that restriction was removed at some point during 4.0 development. The naked underscore name is just a variable that starts with an underscore, but has no more characters. Maybe not a big deal, and I'm blowing it out of proportion.

We could make it a one-character keyword (or other sort of reserved word). I don't think that using the underscore for this feature is very complicated from a technical perspective.

In any case, the aim should be to do what's easiest for users, not what's easiest to implement. Unless the effort to implement this is unreasonable, I wouldn't discount it (at least not for technical reasons).

Another idea would be to use a new keyword, like 'empty' or 'blank' instead of a special symbol (like the dollar sign or the hash character).

Hmm.

Nah, I'm totally against that.

new topic     » goto parent     » topic index » view message » categorize

21. Re: Multi-assign

Just use $.

Quick. Easy. Solved. Next issue!

new topic     » goto parent     » topic index » view message » categorize

22. Re: Multi-assign

I still like -,

{ -, lastname } = parse_name("John Doe") 

Sure, it is used in math but given the context it's pretty easy to determine it's not subtracting any numbers. Also consider my previous statement of making this newly chosen character (whatever it is) valid for function calls instead of just an extra comma:

some_func("John", -, "Doe") 
 
-- vs 
 
some_func("John", $, "Doe") 

Besides, $ requires a shift, - doesn't, that's reason enough grin

Jeremy

new topic     » goto parent     » topic index » view message » categorize

23. Re: Multi-assign

jeremy said...

Besides, $ requires a shift, - doesn't, that's reason enough grin

Yeah, I was looking for a shiftless character. Then you came around. No, wait... What I meant was...

The minus sign might work, but the dollar sign is more conspicuous- more full-bodied.

new topic     » goto parent     » topic index » view message » categorize

24. Re: Multi-assign

I'd prefer not to use '$' as it is already loaded with two meanings and to add a third is probably asking for future problems.

I think the dash '-' is fine for the LHS but not so good on the RHS. It could be a typo on the RHS where someone meant to key negative number as an parameter.

A new keyword is a really bad idea.

The preference for a shift-less character is not so important as the feature would not be a commonly used one. Also, keyboards vary as to which characters are shifted. For example, the tilde '~' is very awkward on some keyboards.

I think we need to have a glyph of some sort, and a visually prominent one would be preferable. We should try to avoid characters that are potentially typos.

So I think we are left with the single characters ... "@%^&*?" , and maybe combinations like "[]".

{ A, @, B }  = SomeFunc(1, @, 2) 
{ A, %, B }  = SomeFunc(1, %, 2) 
{ A, ^, B }  = SomeFunc(1, ^, 2) 
{ A, &, B }  = SomeFunc(1, &, 2) 
{ A, *, B }  = SomeFunc(1, *, 2) 
{ A, ?, B }  = SomeFunc(1, ?, 2) 
{ A, [], B } = SomeFunc(1, [], 2) 
new topic     » goto parent     » topic index » view message » categorize

25. Re: Multi-assign

DerekParnell said...

A new keyword is a really bad idea.

I agree with you, but I am curious as to why you think that.

I just thought using a keyword would be too confusing, as it'd be too easy to think it was a variable name or something.

DerekParnell said...

The preference for a shift-less character is not so important as the feature would not be a commonly used one.

We use shifted characters all the time for more commonly used expressions, like and'ing two sequences together.

DerekParnell said...

I think we need to have a glyph of some sort, and a visually prominent one would be preferable. We should try to avoid characters that are potentially typos.

Agreed. This arguably takes the underscore out of the equation as well (as it could be a typo on either side - variable named "_math" turned into "_,math" or something).

DerekParnell said...

So I think we are left with the single characters ... "@%^&*?" , and maybe combinations like "[]".

{ A, [], B } = SomeFunc(1, [], 2) 

This one I really like. It stands out to me.

Problem is, it could be a double typo ("[]" when "p[0]" was meant for example).

DerekParnell said...
{ A, @, B }  = SomeFunc(1, @, 2) 

I could live with this.

DerekParnell said...
{ A, %, B }  = SomeFunc(1, %, 2) 
{ A, ^, B }  = SomeFunc(1, ^, 2) 
{ A, &, B }  = SomeFunc(1, &, 2) 
{ A, *, B }  = SomeFunc(1, *, 2) 
{ A, ?, B }  = SomeFunc(1, ?, 2) 

These all look like operations to me. Even the caret (we don't use it, but it reminds me of power() in other languages).

new topic     » goto parent     » topic index » view message » categorize

26. Re: Multi-assign

Multi-assign in BASIC is:

a,b,c,d,e = 1

So you need just:

object a,b,c,d,e = 1  --- is it possible in 4.*  now ? 
-- And then you can do: 
procedure ma(object a, object b) 
 if sequence(a) then 
   for i=1 to length(a) do 
        a[i]= b 
   end for 
 elsif atom(a) and atom(b) then 
        a = b 
 else 
 end if        
end procedure 
 
ma({a,b,e}, 2) 
 
?a 
?b 
?c 
?d 
?e 

Regards


kinz

new topic     » goto parent     » topic index » view message » categorize

27. Re: Multi-assign

kinz said...

Multi-assign in BASIC is:

a,b,c,d,e = 1

Sorry, my bad, it doesn't work

new topic     » goto parent     » topic index » view message » categorize

28. Re: Multi-assign

jimcbrown said...
DerekParnell said...

A new keyword is a really bad idea.

I agree with you, but I am curious as to why you think that.

I just thought using a keyword would be too confusing, as it'd be too easy to think it was a variable name or something.

I agree with those reasons, and also believe that we should generally be parsimonious about adding keywords.

jimcbrown said...
DerekParnell said...

I think we need to have a glyph of some sort, and a visually prominent one would be preferable. We should try to avoid characters that are potentially typos.

Agreed. This arguably takes the underscore out of the equation as well (as it could be a typo on either side - variable named "_math" turned into "_,math" or something).

Yes, I agree with these. However, I think I may be the only one who still thinks the $ is perfect.

jimcbrown said...
DerekParnell said...
{ A, @, B }  = SomeFunc(1, @, 2) 

I could live with this.

This is not awful, though I'd always imagined using @ for implicit routine id's or something in the future.

jimcbrown said...
DerekParnell said...
{ A, %, B }  = SomeFunc(1, %, 2) 
{ A, ^, B }  = SomeFunc(1, ^, 2) 
{ A, &, B }  = SomeFunc(1, &, 2) 
{ A, *, B }  = SomeFunc(1, *, 2) 
{ A, ?, B }  = SomeFunc(1, ?, 2) 

These all look like operations to me. Even the caret (we don't use it, but it reminds me of power() in other languages).

Yes. I was thinking modulo (%) and bitwise xor (^).

I think my preferences, so far, in order, are: $, ~, @.

Matt

new topic     » goto parent     » topic index » view message » categorize

29. Re: Multi-assign

I think we may be worrying about multiple uses of a character a bit too much. Just learn the rules of Euphoria and what special characters do. No need to make it overly complex but knowing that $ is "ignore" in a LHS is a pretty easy rule.

One thing people did not comment on is making this "new" ignore character valid in function calls for greater clarity:

procedure greet(sequence name="World", sequence greeting="Hello") 
    printf(1, "%s, %s!\n", { greeting, name }) 
end procedure 
 
greet(,"Goodbye") -- pretty bad IMHO 
greet( $, "Goodbye") -- much nicer 

Discussing this may have an effect on what character we choose.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

30. Re: Multi-assign

The ~ by all means!

It's not currently used by Euphoria, so it's the best, least misunderstandable, most visible possibility. The fact that it is also used to indicate the user's home folder in Linux filenames isn't going to cause a problem.

Just read it as "whatever..."

new topic     » goto parent     » topic index » view message » categorize

31. Re: Multi-assign

Is this meant to be just a placeholder for multi-assign, or is it also meant to be a generic bit bucket variable as some have asked for in the past?

My 2 cents:

$ is okay. I kinda like the way that [] stands out and it meets many other criteria, I don't think that it would be a common typo unless scanning something like "foo[]" becomes an issue.

{[], result} = value(number) 
 
[] = command_line() -- ignore the command line 
new topic     » goto parent     » topic index » view message » categorize

32. Re: Multi-assign

jaygade said...

Is this meant to be just a placeholder for multi-assign, or is it also meant to be a generic bit bucket variable as some have asked for in the past?

My original proposal was just for multi-assign. It seems to be growing into a generic bit bucket.

Matt

new topic     » goto parent     » topic index » view message » categorize

33. Re: Multi-assign

jeremy said...

One thing people did not comment on is making this "new" ignore character valid in function calls for greater clarity

Discussing this may have an effect on what character we choose.

Well, I see this as being not a big deal, beyond that some characters (such as the dash or the hash mark) are more likely to be typos on the RHS than the LHS.

Other than that minor (if pesky) issue, it has no effect on the debate.

new topic     » goto parent     » topic index » view message » categorize

34. Re: Multi-assign

mattlewis said...

My original proposal was just for multi-assign. It seems to be growing into a generic bit bucket.

Matt

I was just wondering because the two ideas seemed kind of related. Not multi-assign and bit bucket, but placeholder and bit bucket.

new topic     » goto parent     » topic index » view message » categorize

35. Re: Multi-assign

jaygade said...
mattlewis said...

My original proposal was just for multi-assign. It seems to be growing into a generic bit bucket.

Matt

I was just wondering because the two ideas seemed kind of related. Not multi-assign and bit bucket, but placeholder and bit bucket.

This seems like a natural development to me.

new topic     » goto parent     » topic index » view message » categorize

36. Re: Multi-assign

DerekParnell said...

I'd prefer not to use '$' as it is already loaded with two meanings and to add a third is probably asking for future problems.

So I think we are left with the single characters ... "@%^&*?" , and maybe combinations like "[]".

{ A, ?, B }  = SomeFunc(1, ?, 2) 

That one makes the most sense to me.

Regarding $ on the RHS, to indicate omitted parameters, you cannot do that as it already has valid meaning:

sequence s 
s = {1,5,7} 
function f(object o) return o end function 
 
? s[f($)]  -- prints 7, as it should 
 
if getc(0) then end if 

Regards, Pete

new topic     » goto parent     » topic index » view message » categorize

37. Re: Multi-assign

petelomax said...

Regarding $ on the RHS, to indicate omitted parameters, you cannot do that as it already has valid meaning:

? s[f($)] 

I wouldn't call that valid. I'd say you've found a new bug in the parser.

Matt

new topic     » goto parent     » topic index » view message » categorize

38. Re: Multi-assign

mattlewis said...
petelomax said...

Regarding $ on the RHS, to indicate omitted parameters, you cannot do that as it already has valid meaning:

? s[f($)] 

I wouldn't call that valid. I'd say you've found a new bug in the parser.

Matt

I used such trick in some programs:

s[rand($)]
new topic     » goto parent     » topic index » view message » categorize

39. Re: Multi-assign

Insolor said...

I used such trick in some programs:

s[rand($)]

I'd vote for that being a bug. Fun, interesting but something that needs to be fixed.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

40. Re: Multi-assign

jeremy said...
Insolor said...

I used such trick in some programs:

s[rand($)]

I'd vote for that being a bug. Fun, interesting but something that needs to be fixed.

Jeremy

Except that there is a problem with calling it a bug; it's documented as legal. Look at the section in the documentation on "Slicing of Sequences". In there we see ...

s[$][1..floor($/2)] -- first half of the last element of s 

Now although it may not be what some intended, it is documented, and what harm or problem does it cause?

new topic     » goto parent     » topic index » view message » categorize

41. Re: Multi-assign

DerekParnell said...

Except that there is a problem with calling it a bug; it's documented as legal. Look at the section in the documentation on "Slicing of Sequences". In there we see ...

s[$][1..floor($/2)] -- first half of the last element of s 

Now although it may not be what some intended, it is documented, and what harm or problem does it cause?

Fascinating. As soon as I saw it, I realized how it worked. And now that you've shown that, I recall that being the original spec. OK, so we don't want to break that, and so if we want to use the same symbol for multi-assign and for "use the default arg", then we obviously can't use $, so I relent. smile

Matt

new topic     » goto parent     » topic index » view message » categorize

42. Re: Multi-assign

mattlewis said...

Fascinating. As soon as I saw it, I realized how it worked. And now that you've shown that, I recall that being the original spec. OK, so we don't want to break that, and so if we want to use the same symbol for multi-assign and for "use the default arg", then we obviously can't use $, so I relent. smile

Matt

Now that you agree with me :)

What about the ! explanation point ?

Bernie

new topic     » goto parent     » topic index » view message » categorize

43. Re: Multi-assign

petelomax said...

Regarding $ on the RHS, to indicate omitted parameters, you cannot do that as it already has valid meaning:

sequence s 
s = {1,5,7} 
function f(object o) return o end function 
 
? s[f($)]  -- prints 7, as it should 
 
if getc(0) then end if 

Regards, Pete

That's not insurmountable. Using $ on the LHS is still unambiguous, and when used on the right side the $ only means omitted when that is the only possible interpretation. If both interpretations are possible, then use the length-of-sequence meaning over the omitted-parameter meaning. That's ok since the user can still just use nothing at all (e.g. "s[f(a, , c)]") to omit the parameter in these cases.

(I was not a fan of using $ in either of these meanings, anyways. $ reminds me too much of M$.)

new topic     » goto parent     » topic index » view message » categorize

44. Re: Multi-assign

mattlewis said...

OK, so we don't want to break that, and so if we want to use the same symbol for multi-assign and for "use the default arg", then we obviously can't use $, so I relent. smile

What about $$$ ? That wouldn't break anything, iiuc.

new topic     » goto parent     » topic index » view message » categorize

45. Re: Multi-assign

DerekParnell said...

I'd prefer not to use '$' as it is already loaded with two meanings and to add a third is probably asking for future problems.

I think the dash '-' is fine for the LHS but not so good on the RHS. It could be a typo on the RHS where someone meant to key negative number as an parameter.

A new keyword is a really bad idea.

The preference for a shift-less character is not so important as the feature would not be a commonly used one. Also, keyboards vary as to which characters are shifted. For example, the tilde '~' is very awkward on some keyboards.

I think we need to have a glyph of some sort, and a visually prominent one would be preferable. We should try to avoid characters that are potentially typos.

So I think we are left with the single characters ... "@%^&*?" , and maybe combinations like "[]".

{ A, @, B }  = SomeFunc(1, @, 2) 
{ A, %, B }  = SomeFunc(1, %, 2) 
{ A, ^, B }  = SomeFunc(1, ^, 2) 
{ A, &, B }  = SomeFunc(1, &, 2) 
{ A, *, B }  = SomeFunc(1, *, 2) 
{ A, ?, B }  = SomeFunc(1, ?, 2) 
{ A, [], B } = SomeFunc(1, [], 2) 

The symbol may represent something that absorbs everything. In physics, this reminds me a black hole. A black hole could be formed by a collapsed star which in turn becomes a little star. 'Little star' is the meaning of the word 'asterisk' (http://en.wiktionary.org/wiki/asterisk).

The symbol of asterisk (asterisk character) is already known and used as "don't care" as in specifying file names (or paths) in CP/M, DOS, Microsoft Windows and Unix-like operating systems. In digital logic, a similar form symbol is used as "don't care": x.

- Fernando

new topic     » goto parent     » topic index » view message » categorize

46. Re: Multi-assign

Some interesting possibilities with LHS symbolic sequences:

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


  • Incrementing several variables:
{a,b,c} += 1


  • Adding different values for different variables:
{a,b,c} += {d,e,f}


  • Doubling several variables:
{a,b,c} *= 2


- Fernando

new topic     » goto parent     » topic index » view message » categorize

47. Re: Multi-assign

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? 
new topic     » goto parent     » topic index » view message » categorize

48. Re: Multi-assign

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

new topic     » goto parent     » topic index » view message » categorize

49. Re: Multi-assign

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

new topic     » goto parent     » topic index » view message » categorize

50. Re: Multi-assign

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 message » categorize

51. Re: Multi-assign

DerekParnell said...

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? 

My take on this was:

{a,b,c} = 1       -- illegal/error 
{a,b,c} @= 1      -- a=1, b=1, c=1 
{a,b,c} = {d,e,f} -- a=d, b=e, c=f 
{a,b,c} @= {d,e,f} -- a={d,e,f}, b={d,e,f}, c={d,e,f} 

Pete

new topic     » goto parent     » topic index » view message » categorize

52. Re: Multi-assign

petelomax said...
DerekParnell said...

I'd prefer not to use '$' as it is already loaded with two meanings and to add a third is probably asking for future problems.

So I think we are left with the single characters ... "@%^&*?" , and maybe combinations like "[]".

{ A, ?, B }  = SomeFunc(1, ?, 2) 

That one makes the most sense to me.

I think I have come around to this idea. I've updated the code, and added eubins for Windows / Linux, 32 and 64-bit here.

I also updated it so that you can use ? for default parameters in routine calls.

Matt

new topic     » goto parent     » topic index » view message » categorize

53. Re: Multi-assign

mattlewis said...

I also updated it so that you can use ? for default parameters in routine calls.

I like that this is optional (doesn't break existing code). You could issue a warning when -strict is in effect and the ? is missing from a parameter list.

new topic     » goto parent     » topic index » view message » categorize

54. Re: Multi-assign

DerekParnell said...
mattlewis said...

I also updated it so that you can use ? for default parameters in routine calls.

I like that this is optional (doesn't break existing code). You could issue a warning when -strict is in effect and the ? is missing from a parameter list.

Yes, I didn't put in the warning yet, but that was the plan.

Matt

new topic     » goto parent     » topic index » view message » categorize

55. Re: Multi-assign

Very nice!

new topic     » goto parent     » topic index » view message » categorize

56. Re: Multi-assign

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 message » categorize

57. Re: Multi-assign

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

Yes, this is a general issue, and so you should only use multi-assignment where applicable. In this aspect, it's no different than returning to an object and testing the type. The multi-assignment method will hopefully encourage using a specific element to declare success like value() does, since it's easier to detect invalid values.

bill said...

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

Yes, that's an error. Don't do that. But if you do, euphoria will tell you about it.

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.

I disagree. It's telling the function to disregard what's being passed there and use the default.

bill said...

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.

No, syntactically, they are not identical, any more than their atomic equivalents are.

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 like the sequence notation, since it's a clear indicator that you're expecting a sequence with at least a certain number of elements. It's true that euphoria's assignment operator is the same as its equality operator, but I don't think this causes as much confusion as you imply.

I guess you could write some obfuscated code (I think PeteL wrote some of the best of this genre) where you write statements deceptively across lines, but I don't believe that the syntax is ambiguous itself.

Matt

new topic     » goto parent     » topic index » view message » categorize

58. Re: Multi-assign

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 message » categorize

59. Re: Multi-assign

bill said...

I have viewed this thread with dismay.

Good. Not that I agree with you here but its good that we speak up when we have an issue about the direction of the language.

bill said...

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

I can see how the LHS use of the brace-pair looks like a sequence creation operation when it actually isn't that at all. This is a classic reuse of the limited character set available to use to mean different things depending on the context its used in. There are already a number of such re-uses in Euphoria, such as '=', which can mean an assignment or an equality test depending on where one uses it. Another is the parenthesis-pair, which can delineate a set of function arguments or impose a precedence order for expression evaluation.

We chose the brace-pair for this new feature to hint to the code reader that a sequence is involved, but in this case a sequence is being de-constucted rather than being constructed.

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

The idea is that one would use multi-assign when it makes sense and when it would not fail. So if one uses it for functions that return an atom, you're doing it wrong.

bill said...

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

I like to think of it more as a placeholder. So I regard it more as saying ... 'this position in the list is not being used by me'.

bill said...

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.

Not quite accurate. The parser can distinguish between the two uses, just as it can with the '=' symbol. The rule is simply when the scanner finds '{' as the first character at the start of a statement, it assumes that as multi-assignment is being written. It then goes on to validate that assumption and if true, generates the appropriate Intermediate Language code.

A multi-assignment LHS list is illegal if it contains any literals. Thus {1,2,3} will fail.

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.

As I said earlier, we could have used something else, but we wanted to keep some link to a sequencing sort of operation - in this case a de-sequencing one.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu