develooper Front page | perl.perl5.porters | Postings from January 2008

For 5.12: extra stricture for hard refs

Thread Next
From:
Aristotle Pagaltzis
Date:
January 24, 2008 17:11
Subject:
For 5.12: extra stricture for hard refs
Message ID:
20080125011218.GT31127@klangraum
Hi all,

there should be a new stricture to forbid treating a hardref as
anything other than a hardref (ie throw an exception if it’s ever
numified or stringified).

The only legitimate use case this would make hard would be
referential equality comparisons, which Perl traditionally does
not offer an operator for – instead you’re supposed to use
numerical equality of numified references. Considering that Perl
favours monomorphic operators and value type coercion, I actually
find it surprising and regrettable that there’s no `refeq`
operator for this instead.

So there should be one.

It would obviate the need to ever implicitly numify references.
(Scalar::Util::refaddr is available if you need to do it
explicitly.) Stringifying hard refs is basically never necessary;
for debugging purposes there could be a Scalar::Util function to
do that.

So the total feature in summary would be:

• use strict 'hardrefs';
• refeq
• Scalar::Util::refstr

How much work might that be? (Mostly the #1 item; I know the
others are SMOPs.)

-- 
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1}
&Just->another->Perl->hack;
#Aristotle Pagaltzis // <http://plasmasturm.org/>

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