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

Re: run-once code

Thread Previous | Thread Next
From:
Richard Nuttall
Date:
January 14, 2004 04:32
Subject:
Re: run-once code
Message ID:
40052E91.5080003@nuttall.uk.net
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?
>  
>
How about

$test = sub
{
     if ( some_expensive_lookup_function() >= $MAX_RECORDS )

	   mark_that_we_have_reached_max_records();       

        $test = sub{};
};
                                                                                            

Then call &$test() as needed;

R.
-- 
Richard Nuttall
Nuttall Consulting
www.nuttall.uk.net



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About