For any of you that are interested, here's the code
(based on a combination of your comments). This code
has the following benefits:
1) The calling functions don't need to deal with
passing in a ref [].
2) Multiple "instances" of this function can be used
independently.
3) Only one match clause is needed, so there is no
repeated code (in my case, an exception will be thrown
for EOF).
(*
* Return a function that has the interface of a
* lexer and can act as a token buffer.
*)
let get_token_buffer () =
let token_list = ref [] in
let rec get_token token_list () =
match !token_list with
head :: tail -> token_list := tail;
head
| [] -> token_list := [1; 2; 3]; (* replace me *)
get_token token_list () in
get_token token_list;;
(* Try it out. *)
let token_buffer = get_token_buffer () in
while true do
print_int (token_buffer ())
done
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
-------------------
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