On Wed, Dec 01, 2010 at 03:07:12PM +0000, Ed Avis 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.
It would lead to:
my %h;
$h {foo} = undef;
$h {foo} ->> x; # Dies.
(my $bogus = $h {foo}) ->> x; # No-op;
And perhaps even:
package Foo;
sub new {bless {obj => undef}, shift}
sub meth {$_ [0] {obj}}
package Bar;
use constant OBJ => 0;
sub new {bless [undef], shift}
sub meth {$_ [0] [OBJ]}
my $foo = Foo -> new;
my $bar = Bar -> new;
$foo -> meth ->> x; # Dies.
$bar -> meth ->> x; # No-op.
Please, let's not.
Abigail
Thread Previous
|
Thread Next