OCaml version 4.01.0
# let rec countdown n = if n > 0 then n :: (countdown (n - 1)) else [0];;
val countdown : int -> int list = <fun>
# countdown 10;;
- : int list = [10; 9; 8; 7; 6; 5; 4; 3; 2; 1; 0]
# let cd = countdown;;
val cd : int -> int list = <fun>
# cd 10;;
- : int list = [10; 9; 8; 7; 6; 5; 4; 3; 2; 1; 0]
# let rec countdown n = if n > 0 then n :: (countdown (n - 2)) else [0];;
val countdown : int -> int list = <fun>
# countdown 10;;
- : int list = [10; 8; 6; 4; 2; 0]
# cd 10;;
- : int list = [10; 9; 8; 7; 6; 5; 4; 3; 2; 1; 0]
which is way better in the "principle of least astonishment" department (at least in that case).
> having no global variables, just lexical variables at the top level
That is what OCaml does. Compare Racket:
to OCaml: which is way better in the "principle of least astonishment" department (at least in that case).