At 05:40 01/05/2004 +0900, you wrote:

>On Apr 30, 2004, at 11:58 AM, Jean-Hugues ROBERT wrote:
>
>>At 01:49 01/05/2004 +0900, you wrote:
>>>"Jean-Hugues ROBERT" <jean_hugues_robert / yahoo.com> schrieb im Newsbeitrag
>>>news:6.0.1.1.0.20040430083010.01ce4ab8 / pop.mail.yahoo.com...
>>> > Hi,
>>> >
>>> > For some class I am redefining operator []=(x). Works great.
>>> >
>>> > However when I use it, p xx[] = zz prints zz, not the value
>>> > returned by my method. It makes some sense yet I would have
>>> > thought that the responsibility for that should belong to
>>> > my method. Am I missing something ?
>>>
>>>Yes, it's defined that way (see below).
>>
>>Humm, things are the way they are. When I get annoyed by my
>>kinds questions I end up answering "that's because it's been
>>that way for billion years". I am there quoting the E.T. answer
>>in movie Contact by Robert Zemeckis.
>
>It wasn't always that way. Calling "Foo.bar = value" used to respect 
>#bar='s return value. Later, it was decided by matz that consistancy was 
>best, and the behavior was changed to be consistant with the behavior of 
>the normal assignment operator.
>
>One reason for this is that people would tend to expect this behavior, and 
>perhaps not think about return values when writing the functions. So the 
>following code might not do what is expected.
>
>class Foo
>   def bar=(val)
>     @bar = val.to_i
>   end
>end
>
>f = Foo.new
>g = f.bar = h = "23"
>
>In this case, you would probably expect g, h and f.bar to have been 
>assigned the same way. If the return value of #bar= is respected, however, 
>h and g would have different values.
>
>cheers,
>--Mark

That makes sense. Yet, I am missing the xxx= where I do control the value 
assigned to the lvalue.
I am not alone. At this point there are multiple known cases where it would 
be needed for transparency:
   - Reference, a reference is an indirect mean of access to a lvalue's 
value that is dereferenced when the value is needed and that also makes it 
possible to assign a value to the lvalue at any time.
   - Lazy, a Lazy is a value that is computed when it is needed, not before.
   - Future, a Future is the returned value of an asynchronous method call 
that is waited for when it is needed, not before.
   - LogicVariable, a LogicVariable is a variable that can be free in 
addition to being bound to some value as regular variables are.

Yours,

Jean-Hugues Robert



-------------------------------------------------------------------------
Web:  http://hdl.handle.net/1030.37/1.1
Phone: +33 (0) 4 92 27 74 17