English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Question about try.. with
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-02-19 (00:11)
From: christian konrad <konrad@i...>
Subject: Re: [Caml-list] Question about try.. with
Thanks for all those hints. For the future I will use the beginners 
list, thank you.
But that seams really strange not to have a strictly defined order of 
evaluation. Isn't that really bad if one would like to do some tail 
recursion to get it compiled without recursion but as a loop?

Thanks and cheers,


Jacques Garrigue wrote:

>From: christian konrad <konrad@in.tum.de>
>>I'm doing that:
>>let _ =
>>  try
>>   let infile = open_in !filename in
>>   let rec readIn () =
>>      try
>>         (input_line infile) ^ readIn();
>>      with ee -> "";
>>   in
>>    print_string(readIn () );
>>   "good";
>>  with e -> "";;
>>So why don't I get any output at all? Doesn't "with" erease the raised 
>Because you assume wrongly that input_line will be called before the
>recursive call to readIn. Nothing in the ocaml specification says so
>(evaluation order is left undefined.) In practice the rightmost call
>is done first, which is the recursive call here, but you shouldn't
>depend on it either.
>By the way, it is a bad idea to catch all exceptions. ee should be
>End_of_file and e should be Sys_error _.
>Jacques Garrigue