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=0.0 required=5.0 tests=AWL,HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id E676FBC69 for ; Wed, 18 Jul 2007 18:36:11 +0200 (CEST) Received: from smtp.janestcapital.com (janestcapital.com [66.155.124.107]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l6IGaAxZ029056 for ; Wed, 18 Jul 2007 18:36:11 +0200 Received: from [172.25.129.161] [38.96.172.125] by janestcapital.com with ESMTP (SMTPD-9.10) id A18E043C; Wed, 18 Jul 2007 12:36:30 -0400 Message-ID: <469E4179.90506@janestcapital.com> Date: Wed, 18 Jul 2007 12:36:09 -0400 From: Brian Hurt User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Sam Steingold Cc: Caml List Subject: Re: [Caml-list] Re: modifying hash tables References: <469E3171.7040205@gnu.org> <469E396D.7010508@gnu.org> In-Reply-To: <469E396D.7010508@gnu.org> Content-Type: multipart/alternative; boundary="------------000601010300090004060405" X-Miltered: at concorde with ID 469E417A.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; hash:01 hash:01 hashtable:01 iter:01 hashtable:01 iter:01 stl:01 iterating:01 trade-off:01 ocaml:01 stl:01 iterating:01 trade-off:01 ocaml:01 iterators:01 This is a multi-part message in MIME format. --------------000601010300090004060405 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sam Steingold wrote: >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >Sam Steingold wrote: > > >>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? >> >> > >in case you wondered why I think my code is reasonable: >http://www.lisp.org/HyperSpec/Body/sec_3-6.html > >Hash-table traversal > > For hash table traversal operations, new elements may not be added >or deleted except that the element corresponding to the current hash key >may be changed or removed. > > > See also C++'s STL iterators. The fundamental problem here is that more gaurantees you give as to how things work as you mutate data structures as you iterate over them, the less flexibility you have in how those data structures can be implemented. At the extreme, you have the "one true implementation", which is the only legal implementation. At the other extreme, you have no gaurentees what so ever as to what will happen when you modify a data structure while iterating over it. Lisp chose one trade-off, C++ another, and Ocaml a third. Brian --------------000601010300090004060405 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Sam Steingold wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sam Steingold wrote:
  
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?
    

in case you wondered why I think my code is reasonable:
http://www.lisp.org/HyperSpec/Body/sec_3-6.html

Hash-table traversal

    For hash table traversal operations, new elements may not be added
or deleted except that the element corresponding to the current hash key
may be changed or removed.

  
See also C++'s STL iterators.

The fundamental problem here is that more gaurantees you give as to how things work as you mutate data structures as you iterate over them, the less flexibility you have in how those data structures can be implemented.  At the extreme, you have the "one true implementation", which is the only legal implementation.  At the other extreme, you have no gaurentees what so ever as to what will happen when you modify a data structure while iterating over it.

Lisp chose one trade-off, C++ another, and Ocaml a third.

Brian

--------------000601010300090004060405--