Perl6 Object Oriented Cookbook (v0.2.1)  
Section 2: Attributes and Methods  
 
Recipe 2.11: Creating 'Memoized' Attributes and Methods
Last Updated: Sep 8, 2003
Status: Draft
      Previous Page   Next Page

How important is this problem to you?
  (Login to Vote)
4.67 Rating, 3 Votes  

How acceptable is the proposed solution?
  (Login to Vote)
4.00 Rating, 2 Votes  

Problem:  

You want to create an attribute or method that will be initialized (possibly using a very complex, time-consuming algorithm) the first time it is used, but thereafter uses the initialized, cached value.

Solution:  

Use the is once property:

method foo is once { ... }

Discussion:

Issue: Other possible keyword choices include is cached or is memoized.


Log In to Comment


Login / Edit User Info -- Copyright © 2002 Cognitivity -- Previous Page   Next Page