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 JAA00568; Wed, 17 Dec 2003 09:13:15 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA00545 for ; Wed, 17 Dec 2003 09:13:14 +0100 (MET) Received: from bob.west.spy.net (mail.west.spy.net [66.149.231.226]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hBH8DCX12129 for ; Wed, 17 Dec 2003 09:13:12 +0100 (MET) Received: from [192.168.1.50] (dustinti.west.spy.net [192.168.1.50]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client did not present a certificate) by bob.west.spy.net (Postfix) with ESMTP id B8D7559D1; Wed, 17 Dec 2003 00:13:05 -0800 (PST) In-Reply-To: <200312162230.23322.ijtrotts@ucdavis.edu> References: <203E10E3-2FF3-11D8-A94A-000393CFE6B8@spy.net> <200312162230.23322.ijtrotts@ucdavis.edu> Mime-Version: 1.0 (Apple Message framework v606) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit Cc: caml-list@inria.fr From: Dustin Sallings Subject: Re: [Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml Date: Wed, 17 Dec 2003 00:13:01 -0800 To: ijtrotts@ucdavis.edu X-Mailer: Apple Mail (2.606) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 python's:01 lisp's:01 c's:01 ijtrotts:01 incr:01 val:01 val:01 issac:01 cae:99 ocaml:01 int:01 int:01 rec:01 continuation:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Dec 16, 2003, at 22:30, ijtrotts@ucdavis.edu wrote: > Why not do this: > > # let rec number() = > let i=ref(-1) in fun() -> > incr i; > !i, if !i mod 2 = 0 then "Even" else "Odd";; > val number : unit -> unit -> int * string = > # let n=number();; > val n : unit -> int * string = > # Array.init 10 (fun _ -> n());; > - : (int * string) array = > [|(0, "Even"); (1, "Odd"); (2, "Even"); (3, "Odd"); (4, "Even"); (5, > "Odd"); > (6, "Even"); (7, "Odd"); (8, "Even"); (9, "Odd")|] > > ? > > Issac That's nice. Given this type of construct and raise, is there anything you can do with a continuation that would really be missed? (I'm showing my ignorance of the value of call/cc) -- SPY My girlfriend asked me which one I like better. pub 1024/3CAE01D5 1994/11/03 Dustin Sallings | Key fingerprint = 87 02 57 08 02 D0 DA D6 C8 0F 3E 65 51 98 D8 BE L_______________________ I hope the answer won't upset her. ____________ ------------------- 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