develooper Front page | perl.perl5.porters | Postings from March 2022

Re: Thoughts Towards Type Assertions (was: Re: Pre-RFC: builtin::functions for detecting numbers vs strings)

Thread Previous | Thread Next
From:
Yuki Kimoto
Date:
March 1, 2022 03:45
Subject:
Re: Thoughts Towards Type Assertions (was: Re: Pre-RFC: builtin::functions for detecting numbers vs strings)
Message ID:
CAExogxO19bVMiY_DKGsbM8yYjWJ0YC3dqpKc1_ro+UoFf5CwTw@mail.gmail.com
2022-2-26 0:19 Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:

> On Fri, 25 Feb 2022 15:55:00 +0900
> Yuki Kimoto <kimoto.yuki@gmail.com> wrote:
>
> > 2022-2-25 1:31 Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:
> >
> > >
> > >   * We've finished the PV vs. IVNV split that PR #18958 began, so
> > > now we can perfectly remember "was originally a string" vs "was
> > >     originally a number".
> > >
> > >
> > A Perl big problem is that when a value is touched, the type of value
> > is changed.
> >
> > When a value is created or updated, the type of value is created or
> > changed. This is understandable.
> >
> > However, in current Perl, only touching a value changes the type of
> > the value. This is strange.
> >
> > This reason is that the type of value is used internally and the type
> > is changed freely.
> >
> > Is it possible to design the user type that is not affected by
> > touching?
> >
> > I think it's important that the types of the number and string don't
> > change unintentionally.
>
> That is the entire point of the above-mentioned PR, yes.
>
> It stops perl adding the (public) SvPOK flag to SVs as a side-effect of
> looking at their stringy value. It means that values which started off
> numeric *remain* numeric and never gain that SvPOK flag, meaning you
> can now reliably distinguish that they originally started off as a
> number.
>
> --
> Paul "LeoNerd" Evans
>
> leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
> http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/


OK. I understand now Perl  now reliably distinguishes that they originally
started off as a
number from Perl 5.36+.

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