From: Its Me Date: 2004-04-27T05:24:03+09:00 Subject: Re: Semantics of Multiple Values "Jean-Hugues ROBERT" wrote in message > The multiple assignment reminds me of Prolog's "unification" mechanism. It may be closer to 'deconstruction' or 'pattern matching' in some functional languages. It is still entirely directional, assigning from rhs to lhs, so it is a step short of unification. Multiple value assignment and regexs can both be seen as special cases of 'if pattern matches then assign values' I suppose if done fully, could understand the deconstruction pattern for a, b in all Ruby structures, requiring a clear definition of successful pattern match, and of run-time behavior when pattern match fails: - multiple values: a, b - lists [a, b] - hashes { :k => a, :l=>b} - objects: x.a, x.b - regexps: ?? - ?others? Examples of possible rules: a, b, c = f(x) # provided f(x) returns multiple values # 1st 3 values assigned to a, b, c [a, b, c] = f(x) # provided f(x) returns array # 1st 3 elements assigned to a,b, c {:a=>a, :b=>b} = f(x) # provided f(x) returns hash, h # h[:a] and h[:b] assigned to a, b y.a = f(x) # provided f(x) returns object x with accessor a # assign x.a to y.a y.a, y.b = f(x) # provided f(x) returns object x with accessors a, b # assign x.a, x,b to y.a, y.b It could be a very nice facility if done well and consistently e.g. exploited in "case...when..." statements. It could (not necessarily 'should') potentially be many of the places variables get assigned to today e.g. assignment statements, formal parameters, case statements, ...