From: David Brown <caml-list@davidb.org>
To: Norman Ramsey <nr@eecs.harvard.edu>
Cc: caml-list@inria.fr
Subject: my stupidity and non-tail calls
Date: Wed, 15 Dec 1999 08:39:36 -0800 (PST) [thread overview]
Message-ID: <14423.50248.118601.746540@opus10.davidb.org> (raw)
In-Reply-To: <199912141953.OAA04635@labrador.eecs.harvard.edu>
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
prev parent reply other threads:[~1999-12-15 21:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-12-14 19:53 Norman Ramsey
1999-12-15 10:04 ` Daniel de Rauglaudre
1999-12-16 7:45 ` A common use of try ... with Judicael Courant
1999-12-16 10:43 ` Daniel de Rauglaudre
1999-12-16 11:56 ` Christophe Raffalli
1999-12-15 16:39 ` David Brown [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=14423.50248.118601.746540@opus10.davidb.org \
--to=caml-list@davidb.org \
--cc=caml-list@inria.fr \
--cc=nr@eecs.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox