Created
January 31, 2019 10:18
-
-
Save ashalkhakov/b8ec20765167944ae168be7b69f40a90 to your computer and use it in GitHub Desktop.
Outputting HTML table in ATS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include | |
"share/atspre_staload.hats" | |
#define N 9 | |
#define M 14 | |
implement main0 () = let | |
fun loop1 | |
{i:nat | i <= N} | |
(i: int i): void = | |
if i < N then let | |
val () = println!("<tr>") | |
val () = loop2 (i+1, 0) | |
in end else () | |
// end of [loop1] | |
and loop2 | |
{i,j:nat | i <= N; j <= M} | |
(i: int i, j: int j): void = | |
if j < M then let | |
val () = if (j > 0) then print " " | |
val () = print!("<td>", (i-1)*M+j+1, "</td>") | |
in | |
loop2 (i, j+1) | |
end else let | |
val () = print_newline () | |
val () = println! ("</tr>") in loop1 (i) | |
end // end of [if] | |
// end of [loop2] | |
fun per_month (): void = { | |
var A = @[string][12]( | |
"Січень", "Лютий", "Березень", "Квітень", | |
"Травень", "Червень", "Липень", "Серпень", | |
"Вересень", "Жовтень", "Листопад", "Грудень" | |
) (* end of [var] *) | |
var i: int // = 0 | |
val () = | |
for* {i:nat | i <= 12} .<12-i>. (i: int(i)): (i: int) => (i := 0; i < 12; i := i + 1) | |
{ | |
val () = println!("<section>") | |
val () = println!("<h1>", A.[i], "</h1>") | |
val () = println!("<table>") | |
val () = loop1 (0) | |
val () = println!("</table>") | |
val () = println!("</section>") | |
} | |
} | |
val () = println!("<!DOCTYPE html>") | |
val style = "<style type=\"text/css\" media=\"print\">\n\ | |
@page { size: landscape; }\n\ | |
table { page-break-after: always; }\n\ | |
h1{text-align:center;font-size:24pt;font-weight:bold;text-transform:uppercase;}\n\ | |
td{text-align:center;vertical-align:center;padding:4mm;font-size:18pt;font-weight:bold;}\n\ | |
table {\n\ | |
border-collapse: collapse;\n\ | |
margin-left: auto;\n\ | |
margin-right: auto;\n\ | |
}\n\ | |
table, th, td {\n\ | |
border: 0.5mm solid black;\n\ | |
}\n\ | |
</style>\n" | |
val () = println!("<html><head><title>1</title><meta charset=\"utf-8\" />", style, "</head><body>") | |
val () = per_month () | |
val () = println!("</body></html>") | |
in | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with
patscc -DATS_MEMALLOC_LIBC flats.dats && ./a.out