[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: syntax sugar: treating an object like a method

Eric Mahurin

5/19/2005 1:22:00 AM

>> To a large extent, my reaction to all of these examples
> comes
> >> down, as
> >> it often does, to the question: how would I explain this
> to
> >> someone to
> >> whom I was teaching Ruby (in person or in writing)? I
> think
> >> I would
> >> find it quite difficult to explain that in this:
> >>
> >> s = "hi"
> >> t = s
> >> (s) = "bye"
> >
> > I think this is a good example to show the difference.
> > Programmers need to understand the difference shown above.
> One
> > assigns to a variable and one assigns into an object that a
> > variable has. Both are normal things you would want to do
> and
> > both are assignment-like.
>
> There's no checklist of "normal things" in this context.
> Programming
> languages are allowed to be designed differently :-)
>
> In Ruby's object/reference (variable) model, changing the
> object via
> assignment is *not* normal, and not something I would want to
> do.
> Assignment is to variables, and variables hold references to
> objects
> (or, in some exceptional cases like Fixnums, they are
> immediate
> values).
>
> > Why do some of you think that everything I suggest has to
> do
> > with references?
>
> I don't think that of everything you suggest, but in this
> case:
>
> s = "hi"
> (s) = "bye" # changing the object to which s is a
> reference
>
> it seems to be clearly a way of adding that extra level of
> remove.

It does have the indirection, but it accomplishes almost
nothing that references would. It is just a synonym of
"replace" (if we made this '=' method 'replace').

This half of the proposal is kind-of an extension of RCR 307 -
giving more symmetry between what's allowed on the LHS and RHS
of an assign.

But, nobody like this half of the idea, so I'll drop that part.
The other half - ()/null/default operator (on the RHS) seems
to have more support. It looks like Ruby is at least getting
it for procs/lambda and python has it (__call__).




__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/...