> On Monday, September 2, 2002, at 03:44 AM, Damian Conway wrote:
>
> >> my Date $date .= new('Jun 25, 20002');
> >
> > Hmmmm. That's a very interesting idea.
> > I like it.
>
> Looks pretty groovy to me too. It looks like the .=
> operator, no longer being employed as a string appender,
> now means "use the class I just mentioned".
Not quite. .= means exactly what you'd expect it to mean, "call a method on
the object on the left and assign the result to the variable on the left". So
$date .= new('Jun 25, 2002');
means exactly the same as
$date = $date.new('Jun 25, 2002');
(I'd expect .= to be a valid operator anyway, so one could do $linked_list_item
..= next(), but that's beside the point).
The utility comes when $date.new() calls the (static) new function on the Date
class even if $date is undef. (In essence, "my Date $date;" makes $date an
interesting value of undef, one that's not defined but has a .class() value).
Of course, this doesn't do anything in particular for constructors. We could
also call any static class function on that object.
> If so, perhaps it would only be a small step further for
> it to also mean "and if I don't give the name of the method,
> use new_from_[class of object being passed]". So, the following code
> would call Date::new_from_String, passing 'Sep 21, 1963' as the
> sole argument:
>
> my Date $date;
> $date .= 'Sep 21, 1963';
The problem is that it's not just for static functions. The point is that
"$date .= foo" would be exactly like "$date = $date.foo", and having an
implicit constructor seems really messed up. I guess that would mean that I
could pass Date.'Sep 21, 1963' to anything expecting a Date object. I think
that might be just slightly too magical for comfort. I don't like the idea of
object types automagically converting themselves by context; that way madness
lies. If you want "new" just call it.
--
Adam Lopresto ([EMAIL PROTECTED])
http://cec.wustl.edu/~adam/
Why does man kill? He kills for food. And not only food: frequently
there must be a beverage.
-- Woody Allen, "Without Feathers"