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 UAA13580; Wed, 28 Apr 2004 20:02:49 +0200 (MET DST) 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 UAA13569 for ; Wed, 28 Apr 2004 20:02:46 +0200 (MET DST) Received: from gatekeeper.elmer.external.excelhustler.com (gatekeeper.excelhustler.com [68.99.114.105]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i3SI2jYM007525 for ; Wed, 28 Apr 2004 20:02:45 +0200 Received: from chatterbox.elmer.internal.excelhustler.com (unknown [192.168.0.12]) (using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits)) (Client CN "chatterbox.elmer.internal.excelhustler.com", Issuer "excelhustler.com" (not verified)) by gatekeeper.elmer.external.excelhustler.com (Postfix) with ESMTP id 9F6D1E00E9; Wed, 28 Apr 2004 13:02:44 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by chatterbox.elmer.internal.excelhustler.com (Postfix) with ESMTP id 7092D5C006; Wed, 28 Apr 2004 13:02:44 -0500 (CDT) Received: from wile.internal.excelhustler.com (wile.internal.excelhustler.com [192.168.1.34]) by chatterbox.elmer.internal.excelhustler.com (Postfix) with ESMTP id 5B8B45C005; Wed, 28 Apr 2004 13:02:44 -0500 (CDT) Received: by wile.internal.excelhustler.com (Postfix, from userid 1000) id 2E4933D008; Wed, 28 Apr 2004 13:02:44 -0500 (CDT) Date: Wed, 28 Apr 2004 13:02:43 -0500 From: John Goerzen To: skaller Cc: Jon Harrop , caml-list Subject: Re: [Caml-list] [ANN] The Missing Library Message-ID: <20040428180243.GA4404@excelhustler.com> References: <200404280613.19547.jdh30@cam.ac.uk> <1083141467.9537.845.camel@pelican.wigram> <200404281018.14913.jdh30@cam.ac.uk> <1083151482.9537.904.camel@pelican.wigram> <20040428151818.GC1310@excelhustler.com> <1083169714.9537.1102.camel@pelican.wigram> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1083169714.9537.1102.camel@pelican.wigram> User-Agent: Mutt/1.5.5.1+cvs20040105i X-Scanned-By: clamscan at chatterbox.elmer.internal.excelhustler.com X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 2004:99 2004:99 ignores:01 iterative:01 flags:01 9660:01 glebe:01 ocaml:01 nsw:01 readable:01 snail:02 tree:02 checkout:02 stack:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, Apr 29, 2004 at 02:28:35AM +1000, skaller wrote: > On Thu, 2004-04-29 at 01:18, John Goerzen wrote: > > > In Ocaml you can add state of course. But it's a mess. > > > > I don't find it all that problematic. > > Compare: > > let count = ref 0 in > List.iter > (fun x -> > if !start = 0 then > (start := 1; print "["; print x; ) > else (print ";"; print x) > ) > lst; > if (!start <> 0) then print "]" > > and please don't tell me that isn't a total mess compared with Of course, your example ignores nicer features available for this sort of thing. For instance: let print_list l = let printfunc count item = print_string (if count = 0 then "[" else ";"); print_string item; count + 1 in if (List.fold_left printfunc 0 l) > 0 then print_string "]";; Actually, I think that's more readable than your iterative example below. -- John > proc print_list(){ > read x; > if x == None goto empty; > print "[" > next:> > print x; > read x; > if x == None goto endoff; > print ";"; > goto next: > endoff:> > print "]" > empty: > } > > Notice there are NO FLAGS. The entire state > is represented by the program counter. > In a more complex problem, the entire > state can be local. You can even write > a recursive procedure .. that builds a list .. > or even a tree .. do you want modify > the external state like that, building > a data structure to *emulate* a stack > when you can actually have a real one? > > By the way this is valid, executable Felix. > And of course it works behind the scenes > by emulating a stack :D > > -- > John Skaller, mailto:skaller@users.sf.net > voice: 061-2-9660-0850, > snail: PO BOX 401 Glebe NSW 2037 Australia > Checkout the Felix programming language http://felix.sf.net > > > ------------------- 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