Gprint


#1

Gprint in ATS kind of means ‘generic print’. However it does not have
to do with print. Basically, it supports a generic way to process primitive
data and also defined data structures.

For instance, the following code generates the table at table:

(* ****** ****** )
//
implement
gprint_newline<>() = gprint_string<>("
")
//
(
****** ****** )
//
extern
fun
multable_create(): string = “mac#”
//
implement
multable_create() = let
//
val out = PYlist_nil{string}()
//
implement
gprint_string<>(x) = PYlist_append(out, x)
//
fun
genall
(
i: int
) : void =
(
if (i > 1)
then (genall(i-1); gprint_newline(); genone(i, 1))
else genone(1, 1)
) (
end of [if] )
//
and
genone
(
i: int, j: int
) : void =
if
i >= j
then
(
if j > 1 then gprint(" | ");
gprint!(j, " x ", i, " = ");
if(j
i < 10) then gprint(“0”); gprint(ji); genone(i, j+1)
) (
end of [then] )
//
val () = gprint!("\n")
val () = gprint!("\n")
//
val () = gprint!("\n")
val () = gprint!("<meta charset=“utf-8”>\n")
val () = gprint!(“MultiplicationTable\n”)
val () = gprint!("\n")
//
val () = gprint!("\n")
val () = gprint!(“

Multiplication Table

”)
val () = gprint!("
\n")
val () = genall(9)
val () = gprint!("
\n")
val () = gprint!("\n")
//
val () = gprint!("\n")
//
in
PYlist_string_join(out)
end // end of [multable_create]
//
(
****** ****** *)