Re: Multi-assign
- Posted by _tom (admin) Nov 16, 2011
- 2620 views
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