From: nobu.nokada@... Date: 2002-07-27T14:23:46+09:00 Subject: Re: Call-by-need and/or Delayed Evaluation Hi, At Sat, 27 Jul 2002 13:12:37 +0900, Reginald Braithwaite-Lee wrote: > Has there been any work on using Ruby's closures to implement > call-by-need semantics, such as the freeze and thaw or delay and force > macros in Lisp? Like this? # udelegator.rb by kjana [ruby-list:8239] class UDelegator def initialize(obj) preserved = ::Kernel.instance_methods for t in self.type.ancestors preserved |= t.instance_methods break if t == UDelegator end preserved -= ["__getobj__","to_s","nil?","to_a","hash","dup","==","=~"] for method in obj.methods next if preserved.include? method undef_method method end end def method_missing(msg, *arg, &block) __getobj__.__send__(msg, *arg, &block) end def __getobj__ raise NotImplementError, "need to define `__getobj__'" end end class Promise 0 foo = future {sleep 10; a = Foo.new([]); for i in 1..100; print "#{i} "; a[i] = i; end; puts; a} puts "here is `non touched' future #{foo}" puts "# preserved method call: future is not evaluated here." puts "foo.type = #{foo.type}" puts "some time consuming task take place...." sleep st; puts "# unpreserved method call: future is `touched' here." puts "foo.isa = #{foo.isa}" puts "foo[10] = #{foo[10]}" end -- Nobu Nakada