develooper Front page | perl.perl5.porters | Postings from October 2021

Re: PSC #040(?) - Perl SV Flags special

Thread Previous | Thread Next
From:
Dan Book
Date:
October 15, 2021 15:16
Subject:
Re: PSC #040(?) - Perl SV Flags special
Message ID:
CABMkAVV+10L1daBAf+NLpKWh9fW9VmwYSwnKfGdpaWXFzRwsvA@mail.gmail.com
On Fri, Oct 15, 2021 at 10:34 AM Nicholas Clark <nick@ccl4.org> wrote:

> On Fri, Oct 15, 2021 at 10:18:36AM -0400, Dan Book wrote:
> > On Fri, Oct 15, 2021 at 4:03 AM Nicholas Clark <nick@ccl4.org> wrote:
> >
> > > I'm not sure that we can push this to distinguishing between "started
> as an
> > > integer literal" vs "started a floating point", *and* I'm not sure if
> we
> > > need to. The big problem we're trying to solve here is correctly
> generating
> > > formats such as JSON and YAML that *are* sensitive to strings vs
> numbers,
> > > and I didn't think that they (or their other-language consumers) were
> > > sensitive to "what sort of a number is it?"
> > >
> >
> > I can't speak to the others, but JSON does distinguish integers and
> floats;
> > some implementations have deigned to preserve roundtripping NVs with a
> > trailing '.0' though there are a couple problems with this. Perl NVs pop
> > into existence at some unexpected times, such as the result of 2**2. And
> > this isn't as important IME as creating, say, a JSON document with
> boolean
> > values.
>
> Oh my. How does (or "can?") Javascript itself manage to roundtrip JSON like
> this?
>
>
> How to implement C<**> in perl to return integers for integer input wasn't
> obvious, given that the C library builtins are pow (and also powl these
> days).
>
> Hence it kept its pre-5.8.0 behaviour of always returning an NV.
> It's consistent.
>
> If there's a good way to do it in (or close to) O(1) for integers, I'd
> love to know.
>

** is certainly not the only case which does this unexpectedly. '42' +
'bar' also ends up as an NV, though this is less commonly encountered. See
https://github.com/rurban/Cpanel-JSON-XS/pull/63 for the full discussion.

-Dan

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