From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 0CFC5BC69 for ; Wed, 18 Jul 2007 18:00:58 +0200 (CEST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l6IG0vrA013181 for ; Wed, 18 Jul 2007 18:00:57 +0200 Received: by ug-out-1314.google.com with SMTP id o2so279255uge for ; Wed, 18 Jul 2007 09:00:57 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=UZKoe40E34H7/mKlNET5TncXntArRKDhdVUtPVFk2YBq1InVdEx4Vz96ZczKboGs3Z8ITOHdNRCJR+XmQ3Yioipyb30E6RxfGVwH/CxsMBRkf/qGol6v1ZlrDR+T2wRMIXbtTztNrr5ipbu78lS6TyOAKfWE1Ebo3i64/8M0TUY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=nEXwsnSujSESteoUSF/01Zqmj57YdwyropXpk4xum3DH30LPW4RDXQPS0JPyEei1+8P77JFEEubIUWKW96oTP0nRrGWS2gRUrl/LpUOznAkcZRzlO+1K/keNEov6lKD7tcCxooFs/wNQmQxqTzAiFBKRrKQVvT4N+Gzub7zLq7I= Received: by 10.78.206.9 with SMTP id d9mr499862hug.1184774457099; Wed, 18 Jul 2007 09:00:57 -0700 (PDT) Received: by 10.78.156.10 with HTTP; Wed, 18 Jul 2007 09:00:57 -0700 (PDT) Message-ID: <4a051d930707180900r3b8b64b3pc8316ec0490ca8f7@mail.gmail.com> Date: Wed, 18 Jul 2007 12:00:57 -0400 From: "Christopher L Conway" Sender: christopherleeconway@gmail.com To: "Sam Steingold" Subject: Re: [Caml-list] modifying hash tables Cc: caml-list@inria.fr In-Reply-To: <469E3171.7040205@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <469E3171.7040205@gnu.org> X-Google-Sender-Auth: 8c60f398af4e92c7 X-Miltered: at discorde with ID 469E3939.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; hash:01 hashtbl:01 hashtbl:01 hashtable:01 hash:01 hashtable:01 iter:01 iter:01 beginner's:01 ocaml:01 bug:01 beginners:01 wrote:01 caml-list:01 caml-list:01 Assuming that your question is "is it OK to modify a Hashtbl while you iterate over it?" and assuming that the answer is "maybe, but maybe not" and assuming that I am looking for a way to avoid doing real work, you might try the following: (Hashtbl.fold (fun key data f -> (fun ht -> Hashtable.replace ht key (data+1); f ht)) ht (fun _ -> ())) ht Chris On 7/18/07, Sam Steingold wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I want to modify the _current_ datum in Hashtable.iter, e.g., increment > a count. Is this code valid? > Hashtable.iter ht ~f:(fun ~key ~data -> > Hashtable.replace ht ~key ~data:(data+1)) > (it appears to work, but I was told that "it is not guaranteed to work", > i.e., the documentation does not promise that). > If the above code is wrong, what is TRT? > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.6 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iD8DBQFGnjFxPp1Qsf2qnMcRAhFaAJ0WEo90RwF5e1Ue+0tCdLyW2R5gawCcCJfd > T8szhrihvlLwCh5L+er0N1E= > =9bhb > -----END PGP SIGNATURE----- > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > >