From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA31245; Tue, 1 Jun 2004 17:27:14 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA31815 for ; Tue, 1 Jun 2004 17:27:13 +0200 (MET DST) Received: from pat.uio.no (pat.uio.no [129.240.130.16]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i51FRBSH009097 for ; Tue, 1 Jun 2004 17:27:12 +0200 Received: from mail-mx3.uio.no ([129.240.10.44]) by pat.uio.no with esmtp (Exim 4.30) id 1BVBAV-0000qv-16; Tue, 01 Jun 2004 17:27:11 +0200 Received: from itherther.simula.no ([129.240.228.187]) by smtp.uio.no with esmtp (Exim 4.34) id 1BVB5k-00048d-Ht; Tue, 01 Jun 2004 17:22:16 +0200 From: Hans Ole Rafaelsen Reply-To: hans@simula.no Organization: Simula Research Laboratory To: skaller@users.sourceforge.net Subject: Re: [Caml-list] Lazy recomputing Date: Tue, 1 Jun 2004 17:22:15 +0200 User-Agent: KMail/1.6 Cc: Thomas Fischbacher , caml-list References: <200406011207.33006.hans@simula.no> <1086094794.16811.72.camel@pelican.wigram> In-Reply-To: <1086094794.16811.72.camel@pelican.wigram> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200406011722.15467.hans@simula.no> X-MailScanner-Information: This message has been scanned for viruses/spam. Contact postmaster@uio.no if you have questions about this scanning X-UiO-MailScanner: No virus found X-UiO-Spam-info: not spam, SpamAssassin (score=-5, required 12, UIO_MAIL_IS_INTERNAL -5.00) X-Miltered: at concorde with ID 40BCA04F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; rafaelsen:01 simula:01 caml-list:01 2004:99 2004:99 hashtbl:01 hashtbl:01 int:01 int:01 lazy:02 laziness:02 unit:03 wrote:03 wrote:03 dependent:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tuesday 01 June 2004 14:59, skaller wrote: > On Tue, 2004-06-01 at 21:43, Thomas Fischbacher wrote: > > > Is there some trick to get it recomputed, other that keep a list of all > > > dependent values, and "refresh" the table whenever some value is > > > updated? > > > > This is not what the general concept of laziness is about. > > > > You need something different. > > What he actually needs is a generalisation: a partial evaluator. Thanks, that got me on the right track. The values are stored as functions in the table. That way they are not evaluated during initialization, and can be forced reevaluated when needed. Have to make my own access functions. let _ = List.iter (fun (k,v) -> Hashtbl.add tbl k v) [ ("a", fun () -> 1); ("c", fun () -> ((Hashtbl.find tbl "b") ()) + ((Hashtbl.find tbl "a") ())); ("b", fun () -> 4); ] let find tbl k = Hashtbl.find tbl k () let replace tbl k v = Hashtbl.replace tbl k (fun () -> v) # let _ = find tbl "c";; - : int = 5 # let _ = replace tbl "a" 7;; - : unit = () # let _ = find tbl "c";; - : int = 11 # -- Hans Ole ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners