Don't ask to ask, just ask | |
PerlMonks |
A Lazy Classby Zaxo (Archbishop) |
on Apr 21, 2002 at 14:46 UTC ( [id://160883]=perlquestion: print w/replies, xml ) | Need Help?? |
Zaxo has asked for the wisdom of the Perl Monks concerning the following question: I have use for a boolean class which is lazy evaluated. That is, it will take no value until needed, after which its value is memoized. I want this for testing complicated nests of logical operators, but a similar construction would be useful for expensive functions. I've implemented this in terms of a closure in the constructor and overload 'bool'. I'm not very satisfied with the implementation. The $foo->{peek}{} notation for the closures is really ugly, but I like the way overloading works here. I'd appreciate any suggestions for a cleaner interface. Is there an idiom for this? Would tie help? Here's the module and a demo script: lazybool.pl:
After Compline,
Back to
Seekers of Perl Wisdom
|
|