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

Re: Pre-RFC: Real "boolean" SV type

Thread Previous | Thread Next
From:
ilmari
Date:
August 4, 2021 15:24
Subject:
Re: Pre-RFC: Real "boolean" SV type
Message ID:
878s1hgrlu.fsf@wibble.ilmari.org
"Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> writes:

> I propose the addition of a new SV type, of SVt_BOOL. Should I write an
> RFC?

Yes please!

> This type will act much like the existing "booleans" of PL_sv_no and
> PL_sv_yes, except its type will remain distinct, so it will be possible
> to distinguish "that SV is a boolean". This is a requirement for
> certain kinds of data serialisation - such as JSON or MsgPack - and may
> be useful for many other purposes too.
>
> Still to be determined: a pureperl interface on it. E.g. would this be
> possible:
>
>   use feature 'bool';
>
>   my $yes = true;   # new literal value keywords
>   my $no  = false;  #
>
>   use Scalar::Util 'svtype';
>
>   is( svtype($yes), "BOOL", 'true is SVt_BOOL');

Should these also pass?

    is( svtype(!0) ,"BOOL", 'PL_sv_yes is SVt_BOOL' );
    is( svtype(!1) ,"BOOL", 'PL_sv_no is SVt_BOOL' );

And if so, only in the scope of `use feature 'bool';`, or everywhere?

- ilmari

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