Front page | perl.perl6.language |
Postings from January 2004
Re: run-once code
Thread Previous
|
Thread Next
From:
Dan Brook
Date:
January 14, 2004 06:32
Subject:
Re: run-once code
Message ID:
20040114143146.209ad93b.dbrook@easyspace.com
On Tue, 13 Jan 2004 20:37:21 -0800
David Storrs <dstorrs@dstorrs.com> 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.
Dan
Thread Previous
|
Thread Next