Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* sequencing
@ 1997-06-03  9:04 Jean.Luc.Paillet
  1997-06-03 11:14 ` sequencing Francois Pessaux
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jean.Luc.Paillet @ 1997-06-03  9:04 UTC (permalink / raw)
  To: caml-list

   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 ?

   ?????
**********************************************
££  English version  ££

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







^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1997-06-03 15:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-06-03  9:04 sequencing Jean.Luc.Paillet
1997-06-03 11:14 ` sequencing Francois Pessaux
1997-06-03 11:15 ` sequencing Jean-Christophe Filliatre
1997-06-03 11:56 ` sequencing Michel Quercia
1997-06-03 14:47 ` sequencing Vincent Poirriez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox