Browse thread
[Caml-list] [ANN] The Missing Library
-
John Goerzen
-
Kenneth Knowles
- Alexander V. Voinov
-
John Goerzen
-
Maxence Guesdon
-
John Goerzen
- Maxence Guesdon
-
John Goerzen
-
Alain.Frisch@e...
-
John Goerzen
-
Alain.Frisch@e...
-
Nicolas Cannasse
-
Yamagata Yoriyuki
- Gerd Stolpmann
-
Nicolas Cannasse
-
Yamagata Yoriyuki
- Jacques GARRIGUE
- Nicolas Cannasse
-
Yamagata Yoriyuki
-
Yamagata Yoriyuki
-
Nicolas Cannasse
- oliver@f...
-
Alain.Frisch@e...
-
John Goerzen
- Henri DF
- Shawn Wagner
- james woodyatt
-
Alain.Frisch@e...
- Basile STARYNKEVITCH
-
John Goerzen
- Kenneth Knowles
- Florian Hars
-
Maxence Guesdon
- Eric C. Cooper
-
Kenneth Knowles
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | John Goerzen <jgoerzen@c...> |
| Subject: | Re: [Caml-list] [ANN] The Missing Library |
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