develooper Front page | perl.perl5.porters | Postings from October 2003

Re: RFC: changing behavior of defined() and exists()

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
October 9, 2003 15:20
Subject:
Re: RFC: changing behavior of defined() and exists()
Message ID:
20031010002257.25757ba8.rgarciasuarez@free.fr
Abigail wrote:
> 
> Having said that, I don't think the added convenience for just exists
> outweigths the drawback of added complexity to the language. Perhaps
> if Perl had next to truth/defined/exists a handful of similar notions
> that could have been dealt with in one consistent fashion that this
> patch would be useful. 
> 
> Having said that, I must say that I find that Roy's proposal has some
> interesting ideas.

I found Roy's original proposal in c.l.p.misc more interesting that his
second (extended) one : basically, this was to allow the return value
of defined() and exists() to be used in a lvalue context with ||= and &&=.

Id est :
	defined($foo) ||= 'default';
means
	$foo //= 'default';
and
	exists($hash{key}) &&= 'replacement';
means
	if (exists($hash{key})) { $hash{key} = 'replacement' }

If we keep only this idea, this is only an extension to existing
syntax, backwards-compatible.

The only sane way to implement this is probably with a bunch
of optree rewriting at optimization time. This means that it's
probably possible to implement it with Arthur's optimizer.pm.
And to put it on CPAN and to avoid bloating the core and to
port it to older perls ! yoohoo ! (any takers?)

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