The sections of the ATS Book on functions may want to have an additional
section on scope, for those of us not as familiar with scope in SML. Though
technically the effects are described in the let/in/end section before
functions are introduced, I wanted to double check some scope issues with
functions, e.g.:
#include
"share/atspre_staload_tmpdef.hats"
//
(* ****** ****** *)
staload “prelude/lmacrodef.sats”
staload “libc/SATS/stdio.sats”
fun
outer(a: int): int = let
//
val b = 10 // This is in scope for use in inner()
fun
inner(x: int, y: int, z: int): int = let
in // of [inner]
(x + y + z + b):int
end // of [inner]
//
val b = 10 // This is NOT in scope for use in inner()
val c = ~10000
in // of [outer]
(inner(a, b, c)):int
end // of [outer]
implement main0() =
{
val c = 100
val p = 1
val outnum = outer§
val () = println! (outnum)
}
This was a bit surprising to me at first, but, it does seem convenient for
e.g. loops functions.