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

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

Thread Previous
October 8, 2003 18:02
Re: RFC: changing behavior of defined() and exists()
Message ID:
On Wed, Oct 08, 2003 at 03:47:35PM -0500, Johnson, Roy wrote:
> defined() should evaluate its arguments in a context [I'm using this
> term generically] wherein only undef is false. The normal usage of
> defined() is unchanged: if you give it an undef value, it returns false,
> otherwise, it returns true. However, if you give it a complex Boolean
> argument, all of the logical operators recognize undef as false, and
> everything else as true, and logical operators yield undef instead of
> normal-perl-false.
> Examples:
>     defined($v = a() || b())   ## equivalent to $v = a() // b();
>     defined($v ||= a())        ## equivalent to $v //= a();
>     defined($v = \( $a && $b && $c && 'full'))

Seems like an awfully complex hack for something that's already been rather
handily fixed.

> No new keywords or operators are required for this behavior. It is
> straightforward 

This doesn't strike me as straightforward at all.  In fact, its rather
hackish to have an expression behave so differently as an argument to a

> and provides access to all logical operations, rather
> than being specific to two. 

There's been little call for "defined-and" or "exists-or" operators.

> Disadvantages:
> It still does not make it easier to do something like:
>     $a = a() // b() || c() // d();
>   which would be (as it currently is):
>     defined($a = a()) || ($a = b()) || defined($a = c()) || ($a = d());

A fairly major disadvantage.  That second one is pretty ugly.

> "defined" is still a relatively long word

Another disadvantage is it complicates defined() and exists() in a way that's
fairly difficult to explain.  dor is easy to explain "its like or except it 
checks for just definedness instead of truth".

Finally, this looks like it would be a bitch to implement.

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About