From: Kristof Bastiaensen Date: 2004-04-27T09:19:03+09:00 Subject: Re: Semantics of Multiple Values Hi, On Tue, 27 Apr 2004 03:00:23 +0900, Jean-Hugues ROBERT wrote: > Multiple Values, Assignments and *Unifications* > > This RCR is really nice. > The multiple assignment reminds me of Prolog's "unification" mechanism. > What about some further generalization ? > > Why not a generalized "assign" operator ? Syntax: > assign term1, term2 [, term3 [, ...]] > And of course an "unify" operator, Syntax: > unify term1, term2 [, term3 [, ...]] > > Result > def mymethod(); return 1, [2], 3 end # Returns an Array > a, b, c = mymethod # => 3, a == 1, b == [2], c == 3 > assign [a,[b]], mymethod # => 2, a == 1, b == 2, c unchanged > assign [a,[],c], mymethod # => false, [] instead of [2] > p unify [a,[2],3], mymethod # => true > p unify r, mymethod # => [1,[2],3] > p unify [a,_,_], mymethod # => 1, _ means "ignore me" > This looks very interesting, I hadn't thought so far. (I also don't know so much about Prolog). From the point of view of syntax, it would be hard to implement, because assign [a, [b]], mymethod is already valid syntax, and would have to make assign and unify a special construct or operator. This may be not so clear. I cannot say much more about it since I am not into prolog. > A key benefit of this proposal is that it does not change > the current semantic of returned values. As a result it is > fully backward compatible with existing source code. The current semantic will change anyway (see also Matz slides about Ruby 2.0), because it has some ambiguities. for example: arr = [1, 2, 3] a, b, c = arr #currently a == 1; b == 2; c == 3 #should be a == [1, 2, 3]; b == nil; c == nil > > Would this solution solve the issue that your RCR solves ? > I think a unify operator would be a different addition than what I described in the RCR. > Jean-Hugues > > BTW: It is often said that operator = is unusal because it does > not apply to an object. It could, we would need a BoundVariable > class, close to a Binding, but referencing a specific variable. Yes, I also think that would be nice. Yet another RCR? > > > ------------------------------------------------------------------------- > Web: http://hdl.handle.net/1030.37/1.1 > Phone: +33 (0) 4 92 27 74 17