val _ = Web.Conn.setMimeType("text/html") val print = Web.Conn.write val _ = Web.Conn.write "\n\ \ MSP examples: generating tables in various styles\n\ \ \n\ \ \n\ \

MSP examples: generating tables in various styles

\n\ \ \n\ \ This page was generated " val _ = Web.Conn.write ( Date.toString (Date.fromTimeLocal(Time.now())) ) val _ = Web.Conn.write " to illustrate ML Server Pages.\n\ \ \n\ \ " (* SML script, imperative style *) fun impmktable oprname opr n m = let fun mkcell r s = (print ""; print (Int.toString (opr(r,s)))) fun mkhead i = (print ""; print (Int.toString i)) fun mkrow m r = (print ""; mkhead r; List.tabulate(m, mkcell r); print "\n") in print "
"; print oprname; List.tabulate(m, mkhead); print "\n"; List.tabulate(n, mkrow m); print "
" end val _ = Web.Conn.write "\n\ \ \n\ \ " (* SML script, functional style *) fun funmktable oprname opr n m = let open Msp infix && fun mkcell r s = $ "" && $ (Int.toString (opr(r,s))) fun mkhead i = $ "" && $ (Int.toString i) fun tabulate(n, f) = List.foldr (op&&) Empty (List.tabulate(n, f)) fun mkrow m r = $ "" && mkhead r && tabulate(m, mkcell r) && Nl in $ "
" && $ oprname && tabulate(m, mkhead) && Nl && tabulate(n, mkrow m) && $"
" end val _ = Web.Conn.write "\n\ \ \n\ \ " (* SML script, functional style, using the Msp HTML functions *) fun mspmktable oprname opr n m = let open Msp infix && fun mkcell r s = td($ (Int.toString (opr(r,s)))) fun mkhead i = th($ (Int.toString i)) fun tabulate(n, f) = List.foldr (op&&) Empty (List.tabulate(n, f)) fun mkrow m r = tr(mkhead r && tabulate(m, mkcell r)) && Nl in tablea "BORDER" (tr (th ($oprname && tabulate(m, mkhead))) && Nl && tabulate(n, mkrow m) ) end val _ = Web.Conn.write "\n\ \ \n\ \ " val n = Msp.%%#("nvalue", 6); val m = Msp.%%#("mvalue", 8); val _ = Web.Conn.write "\n\ \ \n\ \

A multiplication table (generated by imperative code)

\n\ \ \n\ \ " val _ = impmktable "*" (op* ) n m val _ = Web.Conn.write "\n\ \ \n\ \

A multiplication table (generated by functional code)

\n\ \ \n\ \ " val _ = Web.Conn.write (Msp.flatten ( funmktable "*" (op* ) n m )) val _ = Web.Conn.write "\n\ \ \n\ \

An addition table (generated by functional code)

\n\ \ \n\ \ " val _ = Web.Conn.write (Msp.flatten ( funmktable "+" (op+ ) n m )) val _ = Web.Conn.write "\n\ \ \n\ \

A subtraction table (generated by functional code using Msp HTML functions)

\n\ \ \n\ \ " val _ = Web.Conn.write (Msp.flatten ( mspmktable "-" (op- ) n m )) val _ = Web.Conn.write "\n\ \ \n\ \

\n\ \ \n\ \ " val now = Date.fromTimeLocal(Time.now()) local open Substring fun drop0 s = string (dropl (fn c => c = #"0") (full s)) in val shortmon = drop0 (Date.fmt "%m" now) val shortday = drop0 (Date.fmt "%d" now) end val _ = Web.Conn.write "\n\ \ \n\ \ \n\ \
Year " val _ = Web.Conn.write ( Date.fmt "%Y" now ) val _ = Web.Conn.write "\n\ \
Month " val _ = Web.Conn.write ( Date.fmt "%m" now ) val _ = Web.Conn.write "\n\ \
Danish date format" val _ = Web.Conn.write ( shortday ^ "/" ^ shortmon ^ " " ^ Date.fmt "%Y" now ) val _ = Web.Conn.write "\n\ \
US date format " val _ = Web.Conn.write ( shortmon ^ "/" ^ shortday ^ "/" ^ Date.fmt "%y" now ) val _ = Web.Conn.write "\n\ \
ISO date format " val _ = Web.Conn.write ( Date.fmt "%Y-%m-%d" now ) val _ = Web.Conn.write "\n\ \
The time now is " val _ = Web.Conn.write ( Date.fmt "%H:%M" now ) val _ = Web.Conn.write "\n\ \
\n\ \ \n\ \ \n\ \ "