From: Lyndon Samson Date: 2005-10-01T22:09:00+09:00 Subject: Re: Lazy evaluaton (was Re: In your opinion....) ------=_Part_5803_18382614.1128172137098 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 10/1/05, Daniel Lewis wrote: > > On 01/10/05, Robert Klemme wrote: > > Devin Mullins wrote: > > > gabriele renzi wrote: > > > > > >> Think for example of the IO monad: it allows you to state that you > > >> should, say, print "hello" before "world". > > >> The rest of the program is still happy, functional and lazy, since h= e > > >> does'nt really care about the console output. > > > > > > The word "lazy", and the impression I was forming about monads from > > > reading these posts, inspired this simple doodad. Is this useful? Is > > > it already implemented in some other Ruby library out there? > > > > > > class Lazy > > > (instance_methods - %w{__send__ __id__}).each {|meth| undef_method > > > meth } def initialize(blk) > > > @blk =3D blk > > > end > > > def method_missing(*a,&b) > > > @inst =3D @blk.call unless defined? @inst > > > @inst.send(*a,&b) > > > end > > > end > > > > > > def lazy(&blk) > > > Lazy.new blk > > > end > > > > Delegate comes to mind. Not really shorter... > > > > require 'delegate' > > class Lazy < Delegator > > alias :init :initialize > > > > def initialize(&b) > > super(nil) > > @bl =3D b > > end > > > > def __getobj__ > > if @bl > > @obj =3D @bl.call() > > init(@obj) > > @bl =3D nil > > end > > @obj > > end > > end > > def lazy(&b)Lazy.new(&b)end > > > > Only advantage seems that one can reuse lib code for delegation and > > initialization. > > > > Kind regards > > > > robert > > > > > > > > oooh my thread has split :) > > I'm going to be noting all this down, Lazy Evaluation is a subject in > Functional Programming and AI. > > Thanks, > > Daniel. > > 'Call by Name' is worth looking up as well :-) -- Into RFID? www.rfidnewsupdate.com Simple, fast, news. ------=_Part_5803_18382614.1128172137098--