develooper Front page | perl.perl5.porters | Postings from July 2017

Re: Behavior of bitwise ops on unencountered wide characters

Thread Previous | Thread Next
From:
demerphq
Date:
July 12, 2017 18:13
Subject:
Re: Behavior of bitwise ops on unencountered wide characters
Message ID:
CANgJU+Xnmi0Uc6t88CArkF2VzqJBEMebDGwWDL9LUPeoMpULAA@mail.gmail.com
On 12 July 2017 at 19:43, Father Chrysostomos <sprout@cpan.org> wrote:
> Karl Williamson wrote:
>> It would be good to have some alternative that requires only a cheaply
>> loaded, or internal module, something named like "Internals" that
>> provides a clear access path for the things we have determined warrant
>> it, such as Graham's use case.  He had to explain to me how it worked,
>> and he had to explain to Yves as well.  That demonstrates is is
>> non-obvious.  When the tools aren't available, people will do clever,
>> but non-maintainable things to get what they need.  But it is best to
>> furnish the tools when it becomes known that they would be useful.
>
> What worries me is that as soon as we have a blessed way of determin-
> ing whether an argument is internally a number, we will end up with
> code that does this:
>
>   sub foo {
>       croak ("Argument is not a number") unless Internals'is_num $_[0];
>       ...
>   }
>
> and then such code stops working with quoted numbers and over-
> loaded objects.
>
> If we do add such a feature, please leave it undocumented, or annotate
> the documentation with warnings that the feature is intended solely
> for serialization, etc., and that using it to validate arguments (or,
> worse, determine dispatch) goes against the spirit of Perl.

I agree. At a certain level the semantics aren't even clear.

For instance we know that "1.23" should be same as 1.23. But what about "1.230".

Depending on your round-trip requirements it may be ok to round trip
"1.230" as 1.23, or it may not.

Using the & "" trick would make the answer be "both are the same as
1.23", I guess. Sereal would say that they are different, and send
"1.230" as a string, and send "1.23" as a number (assuming both had
been numified).

$ perl -MDevel::Peek -le'$s="1.230"; 0+$s; print $s & ""; Dump($s);'
0
SV = PVNV(0x19a0550) at 0x19c1b28
  REFCNT = 1
  FLAGS = (NOK,POK,pIOK,pNOK,pPOK)
  IV = 1
  NV = 1.23
  PV = 0x19b0d80 "1.230"\0
  CUR = 5
  LEN = 16

$ perl -MDevel::Peek -le'$s="1.23"; 0+$s; print $s & ""; Dump($s);'
0
SV = PVNV(0x131c550) at 0x133db28
  REFCNT = 1
  FLAGS = (NOK,POK,pIOK,pNOK,pPOK)
  IV = 1
  NV = 1.23
  PV = 0x132cd80 "1.23"\0
  CUR = 4
  LEN = 16

Zero poses an interesting example:

$ perl -MDevel::Peek -le'$s=" 0 "; 0+$s; print $s & ""; Dump($s);'
0
SV = PVIV(0x144cf60) at 0x1452b28
  REFCNT = 1
  FLAGS = (IOK,POK,pIOK,pPOK)
  IV = 0
  PV = 0x1441d80 " 0 "\0
  CUR = 3
  LEN = 16

$ perl -MDevel::Peek -le'$s=" 00 "; 0+$s; print $s & ""; Dump($s);'
0
SV = PVIV(0x11aaf60) at 0x11b0b28
  REFCNT = 1
  FLAGS = (IOK,POK,pIOK,pPOK)
  IV = 0
  PV = 0x119fd80 " 00 "\0
  CUR = 4
  LEN = 16

$ perl -MDevel::Peek -le'$s="00"; 0+$s; print $s & ""; Dump($s);'
0
SV = PVIV(0x14a5f70) at 0x14abb38
  REFCNT = 1
  FLAGS = (IOK,POK,pIOK,pPOK)
  IV = 0
  PV = 0x149ad90 "00"\0
  CUR = 2
  LEN = 16

$ perl -MDevel::Peek -le'$s="0"; 0+$s; print $s & ""; Dump($s);'
0
SV = PVIV(0x253ef50) at 0x2544b18
  REFCNT = 1
  FLAGS = (IOK,POK,pIOK,pPOK)
  IV = 0
  PV = 0x2533d70 "0"\0
  CUR = 1
  LEN = 16

$ perl -MDevel::Peek -le'$s=0; "".$s; print $s & ""; Dump($s);'
0
SV = PVIV(0x2405f50) at 0x240bb18
  REFCNT = 1
  FLAGS = (IOK,POK,pIOK,pPOK)
  IV = 0
  PV = 0x240d190 "0"\0
  CUR = 1
  LEN = 16

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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