From: Alessandro Baretta <alex@baretta.com>
To: Brian Hurt <brian.hurt@qlogic.com>, Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Map module
Date: Thu, 05 Jun 2003 20:02:00 +0200 [thread overview]
Message-ID: <3EDF8598.6070804@baretta.com> (raw)
In-Reply-To: <Pine.LNX.4.33.0306051107230.2857-200000@eagle.ancor.com>
Brian Hurt wrote:
> On Thu, 5 Jun 2003, Alessandro Baretta wrote:
>
>
> Glancing at the code, it appears to be a height-balanced tree. So
> operations should use only O(log N) stack frames- call it something less
> than 32 stack frames for 80K elements. Which means either there is a bug
> in that code, or your insert routine is not tail-recursive.
>
The insert routine is actually tail recursive, but somewhere
else there is something which is not tail recursive. I have
now tried converting my code to simple read-parse-print tail
recursive functional cycle and still I get a Stack overflow.
Here's the code:
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
***
Ok, now I'm using a "while true" cycle with exceptions. This
simply cannot overflow.
let output_table2 input_ch =
try
while true do
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
with Scanf.Scan_failure (_) -> ()
done
with End_of_file -> ()
And, yes, this does work. So what is wrong with the
recursive version?
Alex
-------------------
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:01 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 [this message]
2003-06-05 18:13 ` jeanfrancois.monin
2003-06-05 18:15 ` Fred Smith
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=3EDF8598.6070804@baretta.com \
--to=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