develooper Front page | perl.perl6.language | Postings from January 2004

Re: run-once code

Thread Previous | Thread Next
Dan Brook
January 14, 2004 06:32
Re: run-once code
Message ID:
On Tue, 13 Jan 2004 20:37:21 -0800
David Storrs <> wrote:

> Given this code:
>     if ( some_expensive_lookup_function() >= $MAX_RECORDS ) {
>        mark_that_we_have_reached_max_records();       
>        return;
>     } 
> After I enter that block once, I never want to evaluate the condition
> again--I want the code to completely disappear from the bytecode (or,
> at least, be jumped around).  How would I do that in Perl 6?

Another approach would be to just memoize the subroutine. Thanks to the
spiffy new subroutine signature syntax it's absurdly easy e.g

  sub some_expensive_lookup_function() is cached { ... }

That's side-stepping the implications of memoizing a subroutine of
course, but it does save maintaining state in user-level code.


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