From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA20468 for caml-redistribution; Wed, 15 Dec 1999 22:18:21 +0100 (MET) 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 RAA02138 for ; Wed, 15 Dec 1999 17:39:55 +0100 (MET) Received: from opus10.davidb.org (adsl-216-103-8-60.dsl.sndg02.pacbell.net [216.103.8.60]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id RAA02564 for ; Wed, 15 Dec 1999 17:39:48 +0100 (MET) Received: (from davidb@localhost) by opus10.davidb.org (8.9.3/8.9.3/Debian/GNU) id IAA04468; Wed, 15 Dec 1999 08:39:36 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14423.50248.118601.746540@opus10.davidb.org> Date: Wed, 15 Dec 1999 08:39:36 -0800 (PST) To: Norman Ramsey Cc: caml-list@inria.fr Subject: my stupidity and non-tail calls In-Reply-To: <199912141953.OAA04635@labrador.eecs.harvard.edu> References: <199912141953.OAA04635@labrador.eecs.harvard.edu> X-Mailer: VM 6.71 under 21.1 (patch 8) "Bryce Canyon" XEmacs Lucid From: David Brown Sender: weis Norman Ramsey writes: > OK, I apologize for bothering everyone. My `tail calls' are actually > sitting inside `try ... with' blocks, so I recognize that these cannot be > optimized since they are in the scope of different handlers. I will > have to find a way to restructure my code. A great pity, since > I like it the way it is... suggestions are welcome. I wonder if this is worthy of the FAQ. I have done the same thing as well. It comes kind of as a consequence of ocaml's philosophy of using exceptions for things such as not-found, and end of file. Doing this cleans up a lot of code, and a few things get a little messier. I don't know if there is a "clean" way to do it, but what I usually do is wrap the item around an option. e.g. let maybe_input_char infile = try Some (input_char infile) with End_of_file -> None then in the code... let next' = maybe_input_char infile in match next' with Some next -> let () = Queue.add next q in ... compressLoop instr' b q csum infile | None -> finishCompressing instr' b q It isn't quite as clean as the exception code, but it is tail-recursive. David Brown