From: "Fred Smith" <fsmith@mathworks.com>
To: "Alessandro Baretta" <alex@baretta.com>,
"Brian Hurt" <brian.hurt@qlogic.com>,
"Ocaml" <caml-list@inria.fr>
Subject: RE: [Caml-list] Map module
Date: Thu, 5 Jun 2003 14:15:39 -0400 [thread overview]
Message-ID: <IIEMJEMIMDMLIIPHPOBLGECHCBAA.fsmith@mathworks.com> (raw)
In-Reply-To: <3EDF8598.6070804@baretta.com>
The question is: Why isn't this function tail-recursive?
>
> let read_cap s = Scanf.sscanf s "%2s %5[0-9]%[^\r\n]%[\r\n]"
> let rec output_table input_ch =
> try
> let line = input_line input_ch in
> let prov, cap = read_cap line (fun p c _ _ -> p, c) in
> Printf.printf "%s\t%s\n" cap prov;
> output_table input_ch
> with
> | End_of_file -> print_string ""
> | Scanf.Scan_failure (_) -> output_table input_ch
>
>
I believe the answer is the try ... with. The pointer to the exception
handler is part of each recursive call and cannot be popped off the stack
until its recursive child returns. Hence the function is not
tail-recursive. Putting the recursive definition inside the try ... with
should solve your problem.
Good luck.
-Fred
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2003-06-05 18:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-05 15:42 Alessandro Baretta
2003-06-05 15:53 ` Dominique Quatravaux
2003-06-05 15:58 ` james woodyatt
2003-06-05 16:25 ` Brian Hurt
2003-06-05 18:02 ` Alessandro Baretta
2003-06-05 18:13 ` jeanfrancois.monin
2003-06-05 18:15 ` Fred Smith [this message]
2003-06-05 18:24 ` Alessandro Baretta
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=IIEMJEMIMDMLIIPHPOBLGECHCBAA.fsmith@mathworks.com \
--to=fsmith@mathworks.com \
--cc=alex@baretta.com \
--cc=brian.hurt@qlogic.com \
--cc=caml-list@inria.fr \
/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