develooper Front page | perl.perl5.porters | Postings from May 2013

Re: Proposal: initial type annotation in SV

Thread Previous | Thread Next
From:
Ken Williams
Date:
May 13, 2013 18:10
Subject:
Re: Proposal: initial type annotation in SV
Message ID:
loom.20130513T200056-472@post.gmane.org
Sébastien Aperghis-Tramoni writes:
> I would like to expose an idea I had to try solving (at least partly)
> the problem of serializing scalar values from Perl.

I recently had this same itch, and I contributed some very simple code to 
the MongoDB project that solves it in a different way:

  https://github.com/mongodb/mongo-perl-driver/pull/63

IMO, it's not helpful to use the *original* data type, because it prevents 
me from casting to the type I actually want.  It's much more useful to 
provide an explicit casting mechanism and then use the resultant type.

Dave Mitchell <davem <at> iabyn.com> writes:
> 
>     * the serialiser documentation could state that for things to be saved
>       as floats, you must do *= 1.0 shortly before saving;

That doesn't actually work:

 % perl -MDevel::Peek -E '$x=1; print Dump $x; $x *= 1.0; $x += 0.0; print 
Dump $x'
SV = IV(0x1fbe7458) at 0x1fbe7468
  REFCNT = 1
  FLAGS = (IOK,pIOK)
  IV = 1
SV = IV(0x1fbe7458) at 0x1fbe7468
  REFCNT = 1
  FLAGS = (IOK,pIOK)
  IV = 1

That was in fact the motivating case behind creating the explicit cast 
functions.

 -Ken


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