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

Re: Semantics of safe-deref

Thread Previous | Thread Next
From:
demerphq
Date:
December 1, 2010 07:14
Subject:
Re: Semantics of safe-deref
Message ID:
AANLkTik0byFM1f9s7xLx219HpCdGniw0sbm0xQzh0YLX@mail.gmail.com
On 1 December 2010 16:07, Ed Avis <eda@waniasset.com> wrote:
> David Golden <xdaveg <at> gmail.com> writes:
>
>>It was described more or less as "if defined, continue, otherwise
>>return undef".
>
> How about 'if exists, continue, otherwise return undef'?
>
>    my %h;
>    $h{foo} = undef;
>    $h{bar}->>x();   # no-op
>    $h{foo}->>x();   # dies?
>
> To my mind, an explicit undef in there indicates something that should barf when
> you try to dereference it, and is different from a missing hash key or array
> entry.
>
> When the LHS is not an array or hash lookup then the test must be definedness
> not existence.  But if it is, we have a choice of semantics.

I have to admit i worry a bit that introducing syntax that makes "key
associated to undef" and "undef by virtue of key not existing"
different things is likely to be a real source of confusion.

OTOH, im not totally against the idea.

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