develooper Front page | perl.perl6.users | Postings from July 2021

Re: Why does .new initialize?

Thread Previous | Thread Next
From:
Elizabeth Mattijsen
Date:
July 19, 2021 08:24
Subject:
Re: Why does .new initialize?
Message ID:
B3E8ABC5-8098-43FF-8C1C-21F10B74D7C0@dijkmat.nl
> On 19 Jul 2021, at 05:49, Peter Scott <Peter@PSDT.com> wrote:
> 
> I'm curious as to why Rat.new initializes instead of leaving as undefined:
> 
> > $*RAKU
> Raku (6.d)
> > my Rat $p
> (Rat)
> > put $p
> Use of uninitialized value $p of type Rat in string context.
> Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful.
>   in block <unit> at <unknown file> line 1
> > my $q = Rat.new
> 0
> > put $q
> 0

If .new wouldn't initialize a type to its basic instantiation, what would be the point of .new then?

FWIW, the same goes for:

    dd Int.new;      # 0
    dd Num.new;      # 0e0
    dd Complex.new;  # <0+0i>
    dd Str.new;      # ""

If you want to leave it undefined, don't call .new on it?

*confused*
Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About