<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/12/777e01692302f33698e7b6cb5d3e6839"
  from="David Brown &lt;caml-list@d...&gt;"
  author="David Brown"
  date="2003-12-17T20:04:11"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml"
  prev="2003/12/f43d6ac0112ef047d18d7386d09e7f89"
  next="2003/12/26fe2242dec8f2671c5ba6b2f7fedc61"
  prev-in-thread="2003/12/8edface9abeaaa61e00ef1a62a6c512c"
  next-in-thread="2003/12/ac2f915dbdd9a3f399cc73b8be16246d"
  prev-thread="2003/12/774646ec595322579ea76517edc01410"
  next-thread="2003/12/49cb44539cd1e5dc776c6a8f345e0a04"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/f0d20744dca590b72fee31849f8ef5a8"
  from="Nuutti Kotivuori &lt;naked+caml@n...&gt;"
  author="Nuutti Kotivuori"
  date="2003-12-16T13:13:20"
  subject="[Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/bf33bfec2c564f71b03f23afcf441aca"
  from="Oleg Trott &lt;oleg_trott@c...&gt;"
  author="Oleg Trott"
  date="2003-12-16T13:28:13"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/052649193f7443e5fad49ddd9dbe05f7"
  from="Nuutti Kotivuori &lt;naked+caml@n...&gt;"
  author="Nuutti Kotivuori"
  date="2003-12-18T00:15:15"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
</msg>
</msg>
<msg 
  url="2003/12/e8f2fdd8daaa77e7297afe895e600af3"
  from="Ville-Pertti Keinonen &lt;will@e...&gt;"
  author="Ville-Pertti Keinonen"
  date="2003-12-16T13:48:01"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/01e78a00f853a1ce4d39b398b9afb114"
  from="Kenneth Knowles &lt;kknowles@u...&gt;"
  author="Kenneth Knowles"
  date="2003-12-16T15:44:06"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/e9d5dc1f43b97ae6ac0b88e55734a825"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-12-16T16:45:41"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/346cf0f17cf25f0a13da2cfa8edf4234"
  from="Ville-Pertti Keinonen &lt;will@e...&gt;"
  author="Ville-Pertti Keinonen"
  date="2003-12-16T18:36:42"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/12/88fc2c8210caaa7c1abe39d783755b7f"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-12-16T17:40:58"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/40790bf3984b821df7900e88d90f42ac"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-12-16T18:10:39"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/5d2b8084aba6efbe7ecad855a7b3fddc"
  from="ijtrotts@u..."
  author="ijtrotts@u..."
  date="2003-12-17T06:29:27"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/1f4371b3bf98c5187ba2a9e7dbda1b49"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-12-17T08:13:15"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
</msg>
<msg 
  url="2003/12/850360ffe8d0d409f2af993875710c0d"
  from="Falk Hueffner &lt;falk.hueffner@s...&gt;"
  author="Falk Hueffner"
  date="2003-12-17T10:36:03"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/0d6d04a011e30722187b8606b72e19f6"
  from="Pierre Weis &lt;pierre.weis@i...&gt;"
  author="Pierre Weis"
  date="2003-12-17T19:14:30"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/8edface9abeaaa61e00ef1a62a6c512c"
  from="Falk Hueffner &lt;falk.hueffner@s...&gt;"
  author="Falk Hueffner"
  date="2003-12-17T19:32:23"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
</msg>
<msg 
  url="2003/12/777e01692302f33698e7b6cb5d3e6839"
  from="David Brown &lt;caml-list@d...&gt;"
  author="David Brown"
  date="2003-12-17T20:04:11"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
</msg>
<msg 
  url="2003/12/ac2f915dbdd9a3f399cc73b8be16246d"
  from="Nicolas Cannasse &lt;warplayer@f...&gt;"
  author="Nicolas Cannasse"
  date="2003-12-18T01:15:27"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/744adfd5672c3969872e3d4872e7741f"
  from="David Brown &lt;caml-list@d...&gt;"
  author="David Brown"
  date="2003-12-18T05:32:02"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
</msg>
<msg 
  url="2003/12/1c4b3799107085f07200a724dd0cc444"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-12-18T06:27:21"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/4a1681fc89e77e8a070727585335ceeb"
  from="David Brown &lt;caml-list@d...&gt;"
  author="David Brown"
  date="2003-12-18T06:46:06"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
</msg>
</msg>
<msg 
  url="2003/12/93c3b2ec873addb64754bf56a09fb0a7"
  from="brogoff@s..."
  author="brogoff@s..."
  date="2003-12-18T18:44:30"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
</msg>
</msg>
</msg>
<msg 
  url="2003/12/f43d6ac0112ef047d18d7386d09e7f89"
  from="brogoff@s..."
  author="brogoff@s..."
  date="2003-12-17T19:43:06"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/e9e19245af4d01fc23cbaecd9a62ba86"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-12-19T13:40:06"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
</msg>
</msg>
</msg>
<msg 
  url="2003/12/a8c52bf4ae153acf2af4c9fccd7a479c"
  from="Nuutti Kotivuori &lt;naked+caml@n...&gt;"
  author="Nuutti Kotivuori"
  date="2003-12-18T00:51:23"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
On Wed, Dec 17, 2003 at 08:14:21PM +0100, Pierre Weis wrote:
&gt; [...]
&gt; &gt; This only works for simple examples. Try for example writing a
&gt; &gt; function which successively yields all possible moves for a chess
&gt; &gt; board. The "yield" operator really helps there.
&gt; 
&gt; Very interesting: please give us the code corresponding to this
&gt; example, in order for us to realize how the full power of the "yield"
&gt; operator helps to solve this problem.

Perhaps this isn't the best example, since the problem is so large.

The icon language has been around with a similar operator for quite a
while.  It is very useful for prolog-type backtracking, since the code
can be written fairly naturally.

However, this construct is fairly easy to implement in regular OCaml.

The following works, but requires -rectypes to compile:

  open Printf
   
  type 'a thump = 'a * (unit -&gt; 'a thump)
   
  (* Return the numbers a through b and stop. *)
  let through a b () : int thump =
    let rec loop num () =
      if num &gt; b then raise End_of_file;
      num, loop (num + 1) in
    loop a ()
    
  (* Sample to show the results. *)
  let show () =
    let rec loop op =
      let num, op = op () in
      printf "%d," num;
      loop op in
    try loop (through 1 10)
    with End_of_file -&gt;
      printf "\n"
    
  let () = show ()

With a bit more work, you can write it without needing the rectypes.  If
the construct is needed, perhaps it could be done in ocamlp4.  It would
probably have to rewrite the iterative constructs recursively, though.

Dave

-------------------
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

</contents>

</message>

