From: David T. <Dav...@un...> - 2008-05-09 13:23:31
|
Hi, I'm currently reviewing my code before sending in a second contribution (this time, a patch to Enum) and I'm a bit puzzled by Enum.init . With current implementation, creating a clone of an enumeration created with [Enum.init n f] is the same thing as calling [Enum.init n f] again. In particular, if one is to iter through both enumerations, [f 0] will be invoked both by the original and by the clone, [f 1] will be invoked both by the original and by the clone, etc. For instance (*start of example*) let print e = Enum.iter (Printf.printf "%i; ") e;; let f x = Printf.printf "\n\t(Evaluating %i)\n" x; x;; let test_1 = Enum.init 5 f;; let test_2 = Enum.clone test_1;; # print test_1;; (Evaluating 0) 0; (Evaluating 1) 1; (Evaluating 2) 2; (Evaluating 3) 3; (Evaluating 4) 4; # print test_2;; (Evaluating 0) 0; (Evaluating 1) 1; (Evaluating 2) 2; (Evaluating 3) 3; (Evaluating 4) 4; (*end of example*) I find this strange and inconsistent with the cloning of enumerations created with [from] or forced. Now, it's rather easy to fix this but I'm wondering if this behaviour is a bug or by design. Cheers, David -- David Teller Security of Distributed Systems http://www.univ-orleans.fr/lifo/Members/David.Teller Angry researcher: French Universities need reforms, but the LRU act brings liquidations. |