Mark J. Reed wrote:

Let me just chime in with my support for John's basic idea.  I would
definitely prefer that it be easy to arrange things such that

$obj.foo = 'bar'

winds up invoking a method on $obj with 'bar' as an argument, rather
than invoking a method on $obj that returns an lvalue to which
'bar' is then assigned. (Yes, like Ruby's def foo=; I have a Rubyometer
and I'm not afraid to use it!) It doesn't need to be the default rw accessor behavior, but I would like it to be accomplishable without
jumping through a lot of hoops.


-Mark

It sounds a lot like C#'s properties, which are in my opinion one of the best things in C#. Nice easy syntax for those as well, although I can't remember it well enough right now to give an example, as I don't generally keep a C# reference lying around at work where I never use it. Effectively though, if you have an object foo with a property bar, things like


foo.bar = 5;

seem to get turned into

foo.set_bar(5);

where set_bar() was pulled from the property declaration's set {} block, where some magic goes on.

However, it would appear that what John is asking for is already possible, just not necessarily particularly obviously, as returning a proxy object to act as the lvalue and then do the appropriate magic would work, but seems a little mucky. Even if that's what happens behind the scenes.

On the other hand, just as a thought from a crazy C++er, couldn't you accomplish a similar effect by defining your $.foo attribute to be of a custom class, then overriding the = operator for that class...

I know, messy messy. Don't go that way. I shouldn't even have thought of it.



Reply via email to