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 TAA07101; Tue, 1 Jun 2004 19:40:05 +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 TAA06972 for ; Tue, 1 Jun 2004 19:40:04 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i51He0SH026599 for ; Tue, 1 Jun 2004 19:40:02 +0200 Received: from [192.168.1.200] (ppp114-11.lns1.syd3.internode.on.net [150.101.114.11]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i51HduZq040845; Wed, 2 Jun 2004 03:09:57 +0930 (CST) Subject: Re: [Caml-list] Lazy recomputing From: skaller Reply-To: skaller@users.sourceforge.net To: hans@simula.no Cc: Thomas Fischbacher , caml-list In-Reply-To: <200406011722.15467.hans@simula.no> References: <200406011207.33006.hans@simula.no> <1086094794.16811.72.camel@pelican.wigram> <200406011722.15467.hans@simula.no> Content-Type: text/plain Message-Id: <1086111595.16811.134.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 02 Jun 2004 03:39:55 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 40BCBF70.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 sourceforge:01 2004:99 rafaelsen:01 hashtbl:01 hashtbl:01 9660:01 glebe:01 nsw:01 snail:02 lazy:02 checkout:02 2037:03 wrote:03 iter:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 2004-06-02 at 01:22, Hans Ole Rafaelsen wrote: > 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); > ] Of course, this will recompute the same result needlessly to make sure it also computes the new result when needed. Also the functions are bound to a particular hashtble, which isn't so nice: might be nicer to write: fun tbl -> find tbl "b" + find tbl "a" and let eval tbl key = find tbl key tbl;; let tbl = create 97;; let eval_tbl key = eval tbl key;; -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- 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