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 KAA27044; Fri, 14 Mar 2003 10:14:34 +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 KAA26875 for ; Fri, 14 Mar 2003 10:14:33 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from giynz (vp191026.reshsg.uci.edu [128.195.191.26]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h2E9EWf16585 for ; Fri, 14 Mar 2003 10:14:32 +0100 (MET) Received: from albro by giynz with local (Exim 3.36 #1 (Debian)) id 18tlG9-00051l-00; Fri, 14 Mar 2003 01:13:49 -0800 Subject: Re: [Caml-list] OCaml popularity From: "Daniel M. Albro" To: Ville-Pertti Keinonen Cc: caml-list@inria.fr In-Reply-To: <2ABB7A8B-55FC-11D7-8D68-000393863F70@exomi.com> References: <2ABB7A8B-55FC-11D7-8D68-000393863F70@exomi.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1047633229.16221.8.camel@giynz> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 Date: 14 Mar 2003 01:13:49 -0800 X-Spam: no; 0.00; ucla:99 caml-list:01 passing:01 0.100:01 ocaml:01 05,:01 rec:01 continuation:02 essentially:02 wrote:03 recursive:03 tail:03 sys:03 let:04 variation:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Well, I'm certainly learning a lot this way, anyway... Might be useful stuff for a tutorial! This continuation- passing style here runs quite fast, by the way -- equivalent to the original exception-for-loop suggestion: real 0m30.056s user 0m29.950s sys 0m0.100s On Fri, 2003-03-14 at 01:05, Ville-Pertti Keinonen wrote: > > Break simulated by continuation passing (I think that's > > what this is -- it looks like a call/cc to me, anyway) > > Sort of, except that the continuation can't be used outside the > function called by escape. Here's a different approach (this is > essentially a variation of the recursive style, because you need to > make sure the continuation is called as a tail call): > > let _ = > let ary = [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12 |] in > let rec loop f j = > if j = 10 || ary.(j) = 5 then f () > else loop f (j + 1) > in > let rec outer i = > if i <= 1_000_000_000 then > loop (fun _ -> outer (i + 1)) 0 > in > outer 1 > > This style is useful in some cases when you can write a significant > part of your program using continuations. -- Daniel M. Albro ------------------- 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