Front page | perl.perl6.language |
Postings from January 2004
Re: run-once code
Thread Previous
|
Thread Next
From:
David Storrs
Date:
January 14, 2004 09:28
Subject:
Re: run-once code
Message ID:
20040114172836.GB11134@megazone.bigpanda.com
On Tue, Jan 13, 2004 at 10:16:48PM -0700, Luke Palmer wrote:
> sub mark_that_we_have_reached_max_records() {
> $max_reached = 1;
> }
>
> if !$max_reached && some_expensive_lookup_function() > $MAX_RECORDS {
> mark_that_we_have_reached_max_records();
> return;
> }
>
> That's a new feature we're adding called "conditional code removal",
> sometimes known as "short circuiting" :-)
Well, not what I asked (the block is not jumped around, just
shortcircuited) and doesn't really address the principle (i.e., how to
manipulate the bytecode at runtime) I was trying to grok, but ok.
[...]
> This could well be something the optimizer does, but assuming otherwise,
> optimized currying could be to our benefit.
>
> sub do_the_loop($x, $seen) {
> while $x --> 0 {
> if $seen || cheap_condition() {
> something();
> }
> last if !$seen && other_cheap_condition();
> }
> return $x;
> }
>
> &do_the_loop.assuming(seen => 1).(
> &do_the_loop.assuming(seen => 0).(100_000));
>
> If curries are subject to a short constant-folding pass, this should
> easily give us the effect we want.
Had to study this for a bit to assure myself it all worked, but cool!
This is exactly what I was looking for. Thanks.
> > (I recall seeing something about how to make assertions drop out, but
> > I want to be able to do this at run-time, not compile-time.)
>
> As uri said, who can tell the difference?
Point.
--Dks
Thread Previous
|
Thread Next