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

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

Thread Previous | Thread Next
Paul "LeoNerd" Evans
August 5, 2021 10:58
Re: Pre-RFC: Real "boolean" SV type
Message ID:
On Thu, 5 Aug 2021 10:52:51 +0000
Nicholas Clark <> wrote:

> I realised (after I sent the mail) that for scalars it's something
> like
> "SV types are about storage"
> "flags are about values"

Yes - how I've usually explained the thing about SVt_NV, SVt_PV and
SVt_PVNV is that the SvTYPE just tells you what C struct type the SV
body has (which will likely be the high-watermark of any type it has
ever had); whereas the flags tell you which subset of those fields is
actually valid at the moment.

> > I'll mention that in the RFC and point out it really does need a
> > flag - SvBOK() or somesuch?  
> It might be possible to implement *without* a flag, as I postulated,
> using PL_Yes and PL_No, and some changes to sv_setsv_flags.
> (Which will need to be changed come-what-may to deal with booleans)
> So I think it "really does" is not correct - "might" is more accurate.

I don't yet have a good thought about "no", but since PL_sv_yes carries
its own stringification PV, it's possible that sv_setsv could notice
it's that special value and store it as-is, with SvLEN == 0, into the
target. So it's now possible to distinguish any true bool value, by

  SvIV(sv) == 1 && SvPVX(sv) == SvPVX(&PL_sv_yes)

I guess we /could/ allocate an empty string (or maybe be really cheeky
and point at the "\0" of the "1\0" of yes), as the SvPVX for no.

But now we're getting into the weeds of implementation. I think my
original discussion has demonstrated that people do feel a need for
this ability - so I'll write the RFC and we can worry about the "how"

Paul "LeoNerd" Evans      |  |

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