develooper Front page | perl.perl6.internals | Postings from February 2001

Re: defined: Short-cutting on || with undef only.

David L. Nicol
February 19, 2001 19:18
Re: defined: Short-cutting on || with undef only.
Message ID:

I think "defined" should be altered so that it only looks like a function,
but in effect alters the tests being made by the thing that is looking at it.

	if (defined $x){  # slower than if ($x){ # or if($x or defined($x))

could be made faster by propagating the "defined" question up the parse tree
to the decision that is being made based on it, and having that decision only
look as far as definition.

> In Perl 5, it would be written `defined($x) ? $x : "N/A"', but this has the
> problem that $x is evaluated twice, so it doesn't work if instead of $x we
> have a function call (or even if $x is tied...).

With the propagation approach, there's no speed penalty for
	defined $x  or $x = "N/A";	# slower than $x ||= "N/A" in perl 5

It's a perl5 speed optimization not a perl6 language change

                      David Nicol 816.235.1187
     Soon to take out full page ads looking for venture capitalists Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About