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 TAA04649; Tue, 16 Dec 2003 19:10:39 +0100 (MET) 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 TAA04612 for ; Tue, 16 Dec 2003 19:10:38 +0100 (MET) Received: from bob.west.spy.net (mail.west.spy.net [66.149.231.226]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hBGIAaH22081 for ; Tue, 16 Dec 2003 19:10:36 +0100 (MET) Received: from [10.9.254.240] (sjc-dist3-e3.2wire.com [63.203.253.2]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client did not present a certificate) by bob.west.spy.net (Postfix) with ESMTP id 56B1059D6; Tue, 16 Dec 2003 10:10:33 -0800 (PST) In-Reply-To: References: Mime-Version: 1.0 (Apple Message framework v606) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <203E10E3-2FF3-11D8-A94A-000393CFE6B8@spy.net> Content-Transfer-Encoding: 7bit Cc: Nuutti Kotivuori , 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: Tue, 16 Dec 2003 10:10:27 -0800 To: Brian Hurt 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 ocaml's:01 c's:01 python's:01 ocaml:01 ocaml:01 continuation:02 first-class:02 wrote:03 behavior:03 exceptions:04 output:05 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Dec 16, 2003, at 10:42, Brian Hurt wrote: > By my measurements, Ocaml's exceptions are faster than C's > setjmp/longjmp. > Ocaml doesn't provide first-class continuations, but most of the things > people actually do with call-cc can be done in other ways in Ocaml. I > don't know what Python's yield instruction does. Simple example: from __future__ import generators def number(max): for i in range(max): if(i % 2 == 0): yield i, "Even" else: yield i, "Odd" for n in number(10): print n The output of this example is as follows: (0, 'Even') (1, 'Odd') (2, 'Even') (3, 'Odd') (4, 'Even') (5, 'Odd') (6, 'Even') (7, 'Odd') (8, 'Even') (9, 'Odd') It's basically a special case of an upward continuation (or is it downward? I'm bad with terminology). I think you can get pretty close to this behavior with streams, but it's still not as easy as a return statement that has a resume type thing. -- Dustin Sallings ------------------- 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