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

Re: Missing sv_numeq() function?

Thread Previous | Thread Next
Paul "LeoNerd" Evans
September 12, 2021 15:59
Re: Missing sv_numeq() function?
Message ID:
On Fri, 20 Aug 2021 11:55:00 +0100
"Paul \"LeoNerd\" Evans" <> wrote:

> I propose adding an API function
>    BOOL sv_numeq(SV *left, SV *right);
> to cover this.

Update: here's an initial attempt, including docs and XS::APItests:

Thinking further about this, I think I'd like to define a new SV_* flag
to request that the function also perform operator overloading. This
new sv_numeq() would recognise that flag, and I'd also add support to
the existing sv_eq(). (Which, is stringy. In hindsight it should have
been named sv_streq(), but too late now (unless we rename it maybe?))

Perhaps it would be named something like `SV_TRYAMAGIC`. Or maybe the
less cryptic `SV_OVERLOAD` (though we already have an unrelated flag,
`SV_SKIP_OVERLOAD` which the various sv_2Xv_flags() functions all take).

`SV_OVERLOAD` would be nice, except it's a bit messy having some
_flags()-like functions that do overloading by default and have a flag
to tell them not to, vs. other flagsy functions that don't but take a
flag to tell them to.


Maybe I can solve all of these issues in one go, by making a new
sv_streq_flags() which does overload by default, and put that behaviour
in my new sv_numeq_flags() as well, then these functions can all respond
to the same SV_SKIP_OVERLOAD flag in the same way. Then sv_eq() and
sv_eq_flags() become wrappers of sv_streq_flags() which do pass the
SV_SKIP_OVERLOAD flag. I think it would be nice to do overload by
default as that's generally "the nice thing to do", and a flag to turn
it off for specific circumstances.


Paul "LeoNerd" Evans      |  |

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