Version française
Home     About     Download     Resources     Contact us    
Browse thread
Checking for eof
[ 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: [Caml-list] Checking for eof

Youa are actually looking for an eof exception.

Here is a code segment which demonstrates this nicely and won't blow
up the stack.

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 []
;;

Brian