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

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

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
August 5, 2021 10:58
Subject:
Re: Pre-RFC: Real "boolean" SV type
Message ID:
20210805115815.64fa6cb7@shy.leonerd.org.uk
On Thu, 5 Aug 2021 10:52:51 +0000
Nicholas Clark <nick@ccl4.org> 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"
later

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

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