Browse thread
[Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml
[
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: | 2003-12-17 (08:13) |
From: | Dustin Sallings <dustin@s...> |
Subject: | Re: [Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml |
On Dec 16, 2003, at 22:30, ijtrotts@ucdavis.edu wrote: > Why not do this: > > # let rec number() = > let i=ref(-1) in fun() -> > incr i; > !i, if !i mod 2 = 0 then "Even" else "Odd";; > val number : unit -> unit -> int * string = <fun> > # let n=number();; > val n : unit -> int * string = <fun> > # Array.init 10 (fun _ -> n());; > - : (int * string) array = > [|(0, "Even"); (1, "Odd"); (2, "Even"); (3, "Odd"); (4, "Even"); (5, > "Odd"); > (6, "Even"); (7, "Odd"); (8, "Even"); (9, "Odd")|] > > ? > > Issac That's nice. Given this type of construct and raise, is there anything you can do with a continuation that would really be missed? (I'm showing my ignorance of the value of call/cc) -- SPY My girlfriend asked me which one I like better. pub 1024/3CAE01D5 1994/11/03 Dustin Sallings <dustin@spy.net> | Key fingerprint = 87 02 57 08 02 D0 DA D6 C8 0F 3E 65 51 98 D8 BE L_______________________ I hope the answer won't upset her. ____________ ------------------- 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