Re: Generic symbolic sequence assignment
- Posted by mattlewis (admin) Nov 19, 2011
- 1358 views
bill said...
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