1. Generic symbolic sequence assignment
- Posted by Fernando Nov 19, 2011
- 1340 views
Could we use any kind of symbolic sequence in LHS of assignment ?
For example, would the following assignment be possible?
{{a,b},c} = {{d,e},f}
- Fernando
2. Re: Generic symbolic sequence assignment
- Posted by mattlewis (admin) Nov 19, 2011
- 1381 views
Could we use any kind of symbolic sequence in LHS of assignment ?
For example, would the following assignment be possible?
{{a,b},c} = {{d,e},f}
Yes, we could. My first implementation doesn't have this (it's very simple), but there's no technical reason why we couldn't. I wasn't sure if we wanted to go down this route, although I could see the usefulness.
Matt
3. Re: Generic symbolic sequence assignment
- Posted by DerekParnell (admin) Nov 19, 2011
- 1394 views
Could we use any kind of symbolic sequence in LHS of assignment ?
For example, would the following assignment be possible?
{{a,b},c} = {{d,e},f}
Yes, we could. My first implementation doesn't have this (it's very simple), but there's no technical reason why we couldn't. I wasn't sure if we wanted to go down this route, although I could see the usefulness.
Matt
Isn't this simplier and faster ...
a = d b = e c = f
4. Re: Generic symbolic sequence assignment
- Posted by Fernando Nov 19, 2011
- 1358 views
Could we use any kind of symbolic sequence in LHS of assignment ?
For example, would the following assignment be possible?
{{a,b},c} = {{d,e},f}
Yes, we could. My first implementation doesn't have this (it's very simple), but there's no technical reason why we couldn't. I wasn't sure if we wanted to go down this route, although I could see the usefulness.
Matt
Isn't this simplier and faster ...
a = d b = e c = f
Probably, in this specific case. However, the LHS generic symbolic sequence shows its usefulness when the RHS is a function that returns a generic sequence.
- Fernando
5. Re: Generic symbolic sequence assignment
- Posted by bill Nov 19, 2011
- 1362 views
This whole assignment thing is getting out of hand.
According to the manual (and how much user-code?)
{a,b,c} = {d,e,f} returns {a=d,b=e,c=f}
Surely you don't want to break something as basic as that merely to have multiple and/or generic assignment!
6. Re: Generic symbolic sequence assignment
- Posted by mattlewis (admin) Nov 19, 2011
- 1352 views
This whole assignment thing is getting out of hand.
According to the manual (and how much user-code?)
{a,b,c} = {d,e,f} returns {a=d,b=e,c=f}
Surely you don't want to break something as basic as that merely to have multiple and/or generic assignment!
This would still work. The expression you mentioned is a RHS value. There is no LHS value there:
s = {a,b,c} = {d,e,f} -- s is {a=d, b=e, c=f} {a, b, c } = { d, e, f} -- a is assigned the value of d -- b is assigned the value of e -- c is assigned the value of f
In any case, these literal examples are useful for describing what happens, but would not be the most common way they would actually be used. The real utility comes from functions that return multiple results. This avoids the need to store the result, then break out the values, like this:
-- old way: s = value( x ) success = s[1] val = s[2] -- new way: {success, val} = value( x )
Matt
7. Re: Generic symbolic sequence assignment
- Posted by DerekParnell (admin) Nov 19, 2011
- 1325 views
This whole assignment thing is getting out of hand.
According to the manual (and how much user-code?)
{a,b,c} = {d,e,f} returns {a=d,b=e,c=f}
Surely you don't want to break something as basic as that merely to have multiple and/or generic assignment!
I see your point, but the example you have is out of context. The '=' symbol here is not an assignment operator but a comparison operator.
sequence x x = {a,b,c} = {d,e,f} -- The first '=' is assignment, the 2nd is comparison. x = {a=d, b=e, c=f} -- Result in x is a set of 1's and 0's. -- Similar to ... x = {a,b,c} < {d,e,f} x = {a<d, b<e, c<f} -- Result in x is a set of 1's and 0's. -- Currently this next line is invalid in Eu {a,b,c} = {d,e,f} -- An assignment, not a comparison
8. Re: Generic symbolic sequence assignment
- Posted by Fernando Nov 19, 2011
- 1333 views
This whole assignment thing is getting out of hand.
According to the manual (and how much user-code?)
{a,b,c} = {d,e,f} returns {a=d,b=e,c=f}
Surely you don't want to break something as basic as that merely to have multiple and/or generic assignment!
There is no break. That is true only when it represents a comparison (ex.: after an if or while), not an assignment. For example, in the following valid code:
o = o = o
The first '=' is the assignment operator and the second '=' is the equality operator.
- Fernando
9. Re: Generic symbolic sequence assignment
- Posted by DerekParnell (admin) Nov 19, 2011
- 1337 views
Probably, in this specific case. However, the LHS generic symbolic sequence shows its usefulness when the RHS is a function that returns a generic sequence.
Yes, I was thinking of that, but I'm not yet sure of practical that might be.
Here is an obviously contrived example, but it does highlight problems with functions that return different structures based on the input data.
function FUNC(object x) if x > 0 then return {x, {x * x, sqrt(x)}} elsif x = 0 then return x else return {-x, x * x} end if end function {a,{b,c}} = FUNC( userdata )
10. Re: Generic symbolic sequence assignment
- Posted by Fernando Nov 19, 2011
- 1353 views
Probably, in this specific case. However, the LHS generic symbolic sequence shows its usefulness when the RHS is a function that returns a generic sequence.
Yes, I was thinking of that, but I'm not yet sure of practical that might be.
Here is an obviously contrived example, but it does highlight problems with functions that return different structures based on the input data.
function FUNC(object x) if x > 0 then return {x, {x * x, sqrt(x)}} elsif x = 0 then return x else return {-x, x * x} end if end function {a,{b,c}} = FUNC( userdata )
Yes. The generic symbolic sequence assignment is, basically, practical only when the structure of the returned object is constant and compatible with the structure of LHS symbolic sequence. But I think there are many cases in this situation.
- Fernando
11. Re: Generic symbolic sequence assignment
- Posted by petelomax Nov 19, 2011
- 1314 views
Could we use any kind of symbolic sequence in LHS of assignment ?
For example, would the following assignment be possible?
{{a,b},c} = {{d,e},f}
Brilliant idea!
Isn't this simplier and faster ...
a = d b = e c = f
Shame on you!
FWIW, Phix has, or will have:
= - the "ambiguous" (ie context-dependent) operator as per OpenEU
:= - the explicit assignment operator (not properly implemented yet)
== - the explicit equality operator
Note that Phix only permits these explicit operators as an aid for legibility; it does NOT extend functionality, so both
a==0
and
if a:=0 then
generate compiler errors
Pete
Forked into: Phix language
12. Re: Generic symbolic sequence assignment
- Posted by jaygade Nov 20, 2011
- 1305 views
Yuck. I've always despised using ":=" or "==" when "=" works just fine for both assignment and equality.
Just like I never wrote "let" in BASIC.
13. Re: Generic symbolic sequence assignment
- Posted by DerekParnell (admin) Nov 20, 2011
- 1375 views
FWIW, Phix has, or will have:
= - the "ambiguous" (ie context-dependent) operator as per OpenEU
:= - the explicit assignment operator (not properly implemented yet)
== - the explicit equality operator
Yeah, I've consider these and I'm not unhappy about the idea.