On Tue, Sep 03, 2002 at 04:04:13PM -0400, [EMAIL PROTECTED] wrote:
> 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".  

Er, not quite.  It's just like the other X= operators:

        $a = $a + 1             ->              $a += 1
        $a = $a.new(...)        ->              $a .= new(...)

So, in the date example:

        my Date $date .= new('Sep 21, 1963');

it calls $date.new() and since $date is a Date we get Date.new()

(at least that's how I understand things)

But what happens when someone accidently does this:

        my Dog $spot .= Greyhound.new('Lightning');

Somehow I think this will be a common error if this syntax is adopted
(though, in truth, I like it MUCH better than the alternatives I've
seen so far).   I'd expect Perl to complain loudly if someone does the
above, but other people may have other ideas.

> 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';

I too thought of this only it looked more like 

        my Date $date .= 'Sep 21, 1963';        # swell foop

and then I thought things like:

        What happens if there is no constructor?
        How does it know which constructor to call?

The first question is easily answered by "Perl throws an
exception/error". The second question is more of a general question
about method resolution. I don't recall if it's been decided that there
will be a One True Constructor name (somehow I doubt it), or exactly how
you tag methods as being constructors, but if you can do this:

        sub wilma is ctor (str $s) { ... }
        sub betty is ctor (str $s) { ... }

then how does Perl know which constructor to call?  Or would declaring
two constuctors like that cause Perl to carp at you?  (I can't think
of a case where someone would want to have two constructors like that,
but I'm not letting my lack of imagination hinder this discussion  :-)

Anyway, I think the method name should be required.

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]

Reply via email to