Re: RFC 171 (v1) my Dog $spot should call a constructor implicitly

[email protected] (Michael Fowler)
Newsgroups perl.perl6.language.objects
Message-ID <[email protected]>
On Tue, Aug 29, 2000 at 10:00:13PM -0700, Nathan Wiger wrote:
> Matt Youell wrote:
> > 
> > > mainstream OO languages go).  It looks like Dog could be a type of String
> > > subclass.
> > 
> > That was my first thought as well. Besides, I'd rather type:
> > 
> >     my Dog $spot("Spot");
> > 
> > Which says everything that needs to be said without any repetition, and it's
> > fairly intuitive.
> 
> Exactly. I've got to start being more verbose in my examples. Here are
> some different examples and how I personally think they would work given
> this RFC and RFCs 159 and 161:
> 
>    my Dog $spot;              # $spot = Dog->CREATE
>    my Dog $spot (@args);      # $spot = Dog->CREATE(@args)
>    my Dog $spot = "Spot";     # $spot = Dog->CREATE;
> $spot->STORE("Spot")
>    my Dog $spot (@args) = "Spot";   # $spot = Dog->CREATE(@args);
>                                     # $spot->STORE("Spot");

Regarding the STORE call, if RFC 159 gets adopted, sure, why not.  I'll
mention that alternative in the RFC's next version.

I'm not sure about this extra argument syntax.  I didn't really intend the
RFC to replace the traditional constructor call in all cases, but to simply
provide a seemingly more natural and clean way of doing it in the simplest
of cases.

I need to mention the:

    my int $x;
    my int $i = 4;
    my int ($x, $y, $z) = (4, 5, 6);

syntax in the RFC.  It describes more of the intent behind the change.

Sure, the my Dog $spot (@args) looks neat, but it's not any less complex
than a normal constructor call; if anything, it's moreso. There's no current
precedent in Perl for such syntax, and I'm loathe to add it without more
reason.


> Hopefully that's clear enough. And as everyone's noted, nobody's
> claiming you can't do this:
> 
>    my $spot = Dog->new("Spot", { @args });

Indeed, I would also prefer this syntax if there are multiple arguments
(rather than a single scalar to assign).


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.