Version française
Home     About     Download     Resources     Contact us    
Browse thread
Crash reading a file
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Chet Murthy <chet@w...>
Subject: Re: [Caml-list] Crash reading a file
Besides Adam's correct obervation that you're recursing in a non-tail
manner, note also that Ocaml doesn't guarantee any specific
order-of-evaluation, wihch means that the recursive call in the cons
-could- be evaluated before the input_line.  In fact, since the
-current- implementation -does- evaluate in right-to-left order, that
-is- what's going to happen.

# let f x = Printf.fprintf stderr "%s\n" x; flush stderr; x;;
val f : string -> string = <fun>
# let l = ((f"a")::(f"b")::[]);;
b
a
val l : string list = ["a"; "b"]

My guess is, you're getting infinite stack-recursion for even empty
files.  Make your order of evaluation explicit, and you'll only get it
for large files.

--chet--

On Monday 04 February 2008 06:54, tmp123 wrote:
> Hello,
>
> The following program (foo.ml):
>
> value rec read_stdin () =
>   try
>     [ (input_line Pervasives.stdin) :: (read_stdin ()) ]
>   with [ End_of_file -> [] ];
>
> value main () =
>   read_stdin();
>
> main();
>
>
> when compiled with "ocamlopt -pp camlp4r foo.ml" and executed "./a.out",
> produces a segmentation fault, but I'm not able to find why.
>
> Please, has someone any sugestion?
>
> Thanks a lot.
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs