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

Re: Pre-RFC: builtin:: functions for detecting numbers vs strings

Thread Previous | Thread Next
From:
Arne Johannessen
Date:
March 14, 2022 12:51
Subject:
Re: Pre-RFC: builtin:: functions for detecting numbers vs strings
Message ID:
240A04B8-720A-4D58-BABD-DFD5F15C88E4@thaw.de
Yuki Kimoto wrote:
> 
> My understanding:
> 
> Perl 5.36+ can detect a string and a number completely.
> 
>   a string - SvPOK
>   a number - (SvIOK or SvNOK) and not SvPOK


No, I think Perl has always been able to do this. Deep down, it is currently implemented like this:

    is a string - SVp_POK
    is a number - SVp_IOK or SVp_NOK

Note that scalars can be, and indeed often are, strings and numbers at the same time. The new feature in 5.36 is that Perl can now also detect if a value /started/ as a string or number, which is important to know in some rare use cases:

    created as string - SVf_POK
    created as number - (SVf_IOK or SVf_NOK) and not SVf_POK

Any proposed name needs to reflect this distinction.

Thus, variations of these would probably work:
- created_as_number
- initialized_as_number

While variations of these will not work:
- is_number
- treat_as_number

(I share Ovid's doubts about "canonically".)


-- 
Arne Johannessen
<https://arne.johannessen.de/>




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