At 09:29 AM 5/2/2001 -0700, Larry Wall wrote:
>H.Merijn Brand writes:
>: wanting the side effects of grep/map finishing over all elements (which 
>could
>: of course be from a tied array or database connection)
>
>If we do that kind of optimization, then we would certainly provide
>some kind of easy syntax to defeat it.

There are a lot of side-effect things that I'd personally love to be able 
to optimize out, and this is one of them.

Generally speaking, I think that operations on or involving a variable 
should be up for grabs to the optimizer unless there are some lexically 
visible hints that say otherwise. Which means that this:

   sub foo {
     my @bar;
     @bar = grep {/foo/} @_;
     return;
   }
   foo(bar());

would get chewed up by the optimizer such that the foo sub became a noop, 
and the resulting code was the same as:

   bar();

and that this:

   foo(@bar, $baz);

would be a complete noop unless @bar or $baz had some sort of attribute on 
them that forced their evaluation.

Same thing with:

   foreach (1..100) {
    $foo = $_;
   }

should get turned into:

   $foo = 100;

barring any explicit reason that it shouldn't. (Like the compiler sees that 
$foo has the no-short-circuit attribute or something)

I'd really like to get into the details of what is and isn't valid for the 
optimizer to do, though I expect it's still a little early in the 
Apocalypse season for that.

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to