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

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

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
March 11, 2022 10:32
Subject:
Re: Pre-RFC: builtin:: functions for detecting numbers vs strings
Message ID:
20220311103233.75fe5b5c@shy.leonerd.org.uk
On Thu, 10 Mar 2022 19:07:06 -0800
Darren Duncan <darren@darrenduncan.net> wrote:

> On 2022-03-10 6:36 p.m., demerphq wrote:
> > Agreed.
> > 
> > Fwiw The opposite outcome, forcing a value to be a number
> > internally would be:
> > 
> > $num = 0+$num;
> > 
> > Although saying that I wonder what we do these days with
> > 
> > $num += 0;
> > 
> > I haven't checked but I hope the two produce the same outcome.  
> 
> I have zero doubt those produce the same outcome.  Any "foo="
> operators are just shorthands for assigning the result of "foo", and
> so the type of $num must be a number because "+" is the operation.
> 
> BUT, strictly speaking, the equivalence is ACTUALLY these 2:
> 
>    $num = $num + 0;
> 
>    $num += 0;
> 
> It gives the same result the other way only because + is commutative.

These are all good ideas I can include in the unit tests for the new
functions when I get around to writing them - perhaps later today even
:)

-- 
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