Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] looping recursion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: briand@a...
Subject: Re: [Caml-list] looping recursion
After sufficient googling I finally found a post which yields the answer :

let readfile chan =
  let rec loop rlst =
    let line, eof = 
      try
        (input_line chan), false
      with
        | End_of_file -> "", true
    in
      if not eof then
        loop (line :: rlst)
      else
        List.rev rlst
  in
    loop []
;;

but then it gets better.  Imagine my surprise when the following failed:

let data = readfile (open_in "data") in
let split_lines = List.map
                    (fun line ->
                       line;
                    )
                    data
in
  print_string "Done.\n";;

That's just not good !  I can't even use standard map without the
stack blowing up ?  This is a Bad Thing (TM).

Oh but wait. I peruse the manual.  map_rev is what I want.

So I'm going to make a bold statement that .map which blows up
shouldn't even exist and .rev_map should be renamed to .map.

Naturally someone will be telling me very shortly why you can't do this...

Brian

-------------------
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