develooper Front page | perl.perl5.porters | Postings from November 2010

Re: Semantics of safe-deref

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
November 30, 2010 06:32
Subject:
Re: Semantics of safe-deref
Message ID:
20101130143205.GJ24189@plum.flirble.org
On Mon, Nov 29, 2010 at 09:37:07PM +0000, Zefram wrote:
> Jesse Vincent wrote:
> >safe-dereferencing arrow
> 
> I think this name for it is problematic.  There are many types of safety.
> For me, actually, I don't think of the semantics I'm looking for as
> safety at all: I think of them as a shorthand.
> 
> >"If the dereference of the left hand side succeeds,
> 
> Which dereference, and what constitutes success?  For $lhs->[0], there's
> an array dereference, and it obviously fails if $lhs is not a reference
> to an array or something with @{} overloading.  But if there is such
> overloading, does that constitute success?  If the @{} overload method
> dies, was that a failure of dereferencing?  But that's the easy case.
> For $lhs->method, is the dereferencing a success if $lhs is a reference
> to a blessed object?  Or does the method lookup constitute part of the
> dereferencing too?  Or the method execution?
> 
> >I suspect that ->? is going to be more interestingly useful,
> 
> I suspect that it would hide a lot of bugs.

This is my suspicion too.
I was assuming that the operator was

   SvGETMAGIC(sv);
   SvOK(sv)
   ? ... /* do the appropriate dereference, calling overloading if necessary */
   : sv;

(given that sv at that point will be undef)

and that anything that is defined-but-not-a-reference will explode under
strict 'refs', and be treated as a symbolic reference (or explode) when
not under strict refs.

Nicholas Clark

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