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 UAA01028; Wed, 17 Dec 2003 20:32:23 +0100 (MET) 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 UAA00987 for ; Wed, 17 Dec 2003 20:32:21 +0100 (MET) Received: from mx5.informatik.uni-tuebingen.de (mx5.Informatik.Uni-Tuebingen.De [134.2.12.32]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hBHJWKH25166; Wed, 17 Dec 2003 20:32:21 +0100 (MET) Received: from localhost (loopback [127.0.0.1]) by mx5.informatik.uni-tuebingen.de (Postfix) with ESMTP id 2BC9011C; Wed, 17 Dec 2003 20:32:20 +0100 (NFT) Received: from mx3.informatik.uni-tuebingen.de ([134.2.12.26]) by localhost (mx5 [134.2.12.32]) (amavisd-new, port 10024) with ESMTP id 30830-01; Wed, 17 Dec 2003 20:32:18 +0100 (NFT) Received: from juist (semeai [134.2.15.66]) by mx3.informatik.uni-tuebingen.de (Postfix) with ESMTP id 3284C134; Wed, 17 Dec 2003 20:32:18 +0100 (NFT) Received: from falk by juist with local (Exim 3.36 #1 (Debian)) id 1AWhP7-0000Nf-00; Wed, 17 Dec 2003 20:32:17 +0100 X-Face: "iUeUu$b*W_"w?tV83Y3*r:`rh&dRv}$YnZ3,LVeCZSYVuf[Gpo*5%_=/\_!gc_,SS}[~xZ wY77I-M)xHIx:2f56g%/`SOw"Dx%4Xq0&f\Tj~>|QR|vGlU}TBYhiG(K:2 Cc: caml-list@inria.fr Subject: Re: [Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml References: <200312171914.UAA00389@pauillac.inria.fr> From: Falk Hueffner Date: 17 Dec 2003 20:32:17 +0100 In-Reply-To: <200312171914.UAA00389@pauillac.inria.fr> Message-ID: <87r7z31br2.fsf@student.uni-tuebingen.de> User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.5 (cabbage) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new (McAfee AntiVirus) at informatik.uni-tuebingen.de X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 python's:01 lisp's:01 c's:01 falk:01 hueffner:01 falk:01 hueffner:01 pierre:01 weis:01 pierre:01 weis:01 python:01 ocaml:01 writes:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Pierre Weis writes: > [...] > > This only works for simple examples. Try for example writing a > > function which successively yields all possible moves for a chess > > board. The "yield" operator really helps there. > > Very interesting: please give us the code corresponding to this > example, in order for us to realize how the full power of the "yield" > operator helps to solve this problem. I don't really know Python well (nor chess)... it would probably look similar to: def moves(board): for x in range(0, 8): for y in range(0, 8): if board.at(x, y) == PAWN: yield Move(x, y, x + 1) elif board.at(x, y) == ROOK: for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: n = 0 while is_on_board(x + n*dx, y + n*dy): yield Move(x, y, x + n*dx, y + n*dy) n += 1 ... -- Falk ------------------- 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