Gnu/Vince
04-04-2002, 12:21 AM
let range ?(l_lim=0) (u_lim) ?(step=1) =
let rec loop n l =
if n = (pred l_lim) then l
else loop (n - step) (n::l)
in
loop (u_lim - 1) []
let print_int_list l =
print_string "[ ";
List.iter (fun n ->
print_int n;
print_char ' ') l;
print_endline "]"
let _ =
try
let l = range (int_of_string Sys.argv.(1)) in
print_int_list l
with
| Failure "int_of_string" ->
print_endline "So long.";
exit 1;
| Invalid_argument "Array.get" ->
print_endline "So long.";
exit 1
Since I'm pretty sure eventually Jeremy will look at this thread, here's the output of the compile command:
% ocamlc fill3.ml -o fill3
File "fill3.ml", line 1, characters 36-37:
Warning: This optional argument cannot be erased
File "fill3.ml", line 25, characters 19-20:
This expression has type ?step:int -> int list but is here used with type
int list
Can you help me?
let rec loop n l =
if n = (pred l_lim) then l
else loop (n - step) (n::l)
in
loop (u_lim - 1) []
let print_int_list l =
print_string "[ ";
List.iter (fun n ->
print_int n;
print_char ' ') l;
print_endline "]"
let _ =
try
let l = range (int_of_string Sys.argv.(1)) in
print_int_list l
with
| Failure "int_of_string" ->
print_endline "So long.";
exit 1;
| Invalid_argument "Array.get" ->
print_endline "So long.";
exit 1
Since I'm pretty sure eventually Jeremy will look at this thread, here's the output of the compile command:
% ocamlc fill3.ml -o fill3
File "fill3.ml", line 1, characters 36-37:
Warning: This optional argument cannot be erased
File "fill3.ml", line 25, characters 19-20:
This expression has type ?step:int -> int list but is here used with type
int list
Can you help me?