From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA29358 for caml-redistribution; Tue, 3 Jun 1997 12:26:02 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA27962 for ; Tue, 3 Jun 1997 10:57:41 +0200 (MET DST) Received: from gyptis.univ-mrs.fr (gyptis.univ-mrs.fr [193.50.130.2]) by nez-perce.inria.fr (8.8.5/8.7.3) with SMTP id KAA19765 for ; Tue, 3 Jun 1997 10:57:38 +0200 (MET DST) From: Jean.Luc.Paillet@lim.univ-mrs.fr Received: from [193.50.130.176] by gyptis.univ-mrs.fr (4.1/1.34) id AA15419; Tue, 3 Jun 97 10:59:16 +0100 Message-Id: <9706030959.AA15419@gyptis.univ-mrs.fr> X-Sender: jluc@gyptis.univ-mrs.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Eudora F1.4.2 Date: Tue, 3 Jun 1997 10:04:55 +0100 To: caml-list@inria.fr Subject: sequencing Sender: weis Quelqu'un pourrait-il m'expliquer pourquoi le sequencement d'une fonction a` effet de bord, telle que "print_string" par exemple, semble inverse' quand elle est appliquée sur une liste au moyen d'un iterateur. Par exemple map print_string ["a" ; "b"] ;; produit ba- : unit list = [(); ()] ce qui implique un parcours de la liste de droite a gauche . Plus curieux, avec une definition recursive "personnelle" de l'iterateur, telle que let rec monmap f liste = match liste with [] -> [] | head :: tail -> (f head) :: monmap f (tail) ;; On pourrait s'attendre ici a ce que "(f head)" soit evalue avant l'appel recursif. He bien non, on obtient encore monmap print_string ["a" ; "b"] ;; ba- : unit list = [(); ()] Quelle est mon erreur d'interpretation ? Doit-on penser que (f head) est empile jusqu'a ce que la fonction termine ? ????? ********************************************** =A3=A3 English version =A3=A3 I don't understand why the sequencing of side effects seems to be inverted, when using "map" , like for example in the following: map print_string ["a" ; "b"] ;; gives ba- : unit list = [(); ()] it means that the list is scanned from the right to the left More surprising, with a recursive hand made definition of "map", such as let rec monmap f liste = match liste with [] -> [] | head :: tail -> (f head) :: monmap f (tail) ;; We also obtain monmap print_string ["a" ; "b"] ;; ba- : unit list = [(); ()] We could thing that "(f head)" is evaluated before the recursive call . What is my mistake ? Does the term "(f head)" pushed on the recursion stack until terminating the recursive calls, before being evaluated ? Thanks for an explanation Kind regards Jean-Luc Paillet (* ------------------------------------------------------------------------ Jean-Luc PAILLET LIM (URA 1787) CMI - Universite de Provence 39 r Joliot Curie 13453 Marseille Cedex 13 FRANCE Tel: (33) 04 91 11 36 10 Fax: (33) 04 91 11 36 02 e-mail: Jean.Luc.Paillet@lim.univ-mrs.fr jluc@gyptis.univ-mrs.fr -------------------------------------------------------------------------- *)