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 SAA05652; Wed, 28 Apr 2004 18:28: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 SAA05641 for ; Wed, 28 Apr 2004 18:28:47 +0200 (MET DST) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i3SGSiYM024516 for ; Wed, 28 Apr 2004 18:28:46 +0200 Received: from [192.168.1.200] (ppp119-113.lns1.syd2.internode.on.net [150.101.119.113]) by smtp3.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i3SGSak2071987; Thu, 29 Apr 2004 01:58:37 +0930 (CST) Subject: Re: [Caml-list] [ANN] The Missing Library From: skaller Reply-To: skaller@users.sourceforge.net To: John Goerzen Cc: Jon Harrop , caml-list In-Reply-To: <20040428151818.GC1310@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> Content-Type: text/plain Message-Id: <1083169714.9537.1102.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 29 Apr 2004 02:28:35 +1000 Content-Transfer-Encoding: 7bit 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 sourceforge:01 2004:99 2004:99 endline:01 endline:01 incr:01 flags:01 9660:01 glebe:01 ocaml:01 ocaml:01 nsw:01 snail:02 tree:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 2004-04-29 at 01:18, John Goerzen wrote: > On Wed, Apr 28, 2004 at 09:24:43PM +1000, skaller wrote: > > On Wed, 2004-04-28 at 19:18, Jon Harrop wrote: > > Control inversion. In Ocaml you can write: > > > > List.iter (fun x -> print_endline x) ["Hello"; "World"];; > > [ snip ] > > > while ( p != e) do print_endline (get p); incr p done; > [ snip ] > > > > The List.iter style HOF is very limited in utility > > in a functional language: there is no state. > > > 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 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