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

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

Thread Previous | Thread Next
Arne Johannessen
March 14, 2022 12:51
Re: Pre-RFC: builtin:: functions for detecting numbers vs strings
Message ID:
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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About