Re: Reuse of computations

davids@ICSI.Berkeley.EDU (David Petrie Stoutamire)
Mon, 18 Sep 1995 23:38:36 GMT

          From comp.compilers

Related articles
Reuse of computations citron@CS.HUJI.AC.IL (1995-09-04)
Re: Reuse of computations snovack@justright.ICS.UCI.EDU (Steven Novack) (1995-09-09)
Re: Reuse of computations pardo@cs.washington.edu (1995-09-11)
Re: Reuse of computations chase@centerline.com (1995-09-12)
Re: Reuse of computations davids@ICSI.Berkeley.EDU (1995-09-18)
| List of all articles for this month |

Newsgroups: comp.compilers
From: davids@ICSI.Berkeley.EDU (David Petrie Stoutamire)
Keywords: optimize
Organization: International Computer Science Institute, Berkeley, CA, U.S.A.
References: 95-09-053 95-09-100
Date: Mon, 18 Sep 1995 23:38:36 GMT

David Chase <chase@centerline.com> wrote:
>I also recall (don't know it was ever published) that someone once
>wrote a "memoizing functional" in Russell -- in theory, a sick person
>might be able to do this in C++ with a template (I am sorely tempted
>to try).


Here's one written in Sather:


        class MEMOIZE{DOMAIN,RANGE} is


private attr h:FMAP{DOMAIN,RANGE};
private attr r:ROUT{DOMAIN}:RANGE;


-- memoize takes a bound routine and returns another bound
-- routine which stores every computed value in a map; these are
-- looked up and do not have to be recomputed in the future.
memoize(r:ROUT{DOMAIN}:RANGE):ROUT{DOMAIN}:RANGE is
help_ob::=new;
help_ob.h:=#FMAP{DOMAIN,RANGE};
help_ob.r:=r;
return #ROUT(helper(help_ob,_));
end;


private helper(ob:SAME,d:DOMAIN):RANGE is
if ob.h.test(d) then return ob.h.get(d);
else
res::=ob.r.call(d);
ob.h:=ob.h.insert(d,res);
return res;
end;
end;
        end;




  - Dave
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.