From: Kirk Haines Date: 2005-10-02T00:18:15+09:00 Subject: Re: Lazy evaluaton (was Re: In your opinion....) On Saturday 01 October 2005 8:47 am, Kirk Haines wrote: > In the original example, it illustrated how, because lambdas implement #[], > one could have either a memoizing or a nonmeoizing FUN[] depending on a > configuration value. To followup: def create_calculator_object(memoize, &b) memoize ? Hash.new {|h,k| puts "memoizing #{k}"; h[k] = b.call(k)} : b end a = create_calculator_object(true) {|k| (k * 10000007) % 20} b = create_calculator_object(false) {|k| (k * 10000007) % 20} irb(main):007:0> a[5] memoizing 5 => 15 irb(main):008:0> a[5] => 15 irb(main):009:0> b[5] => 15 Kirk Haines