add function in imperative shell to save export string, and fix errors in generating export string from functional core

This commit is contained in:
2025-07-12 19:34:52 +01:00
parent dbb1676fbe
commit 31bc8485f3
3 changed files with 12 additions and 39 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -525,7 +525,7 @@ struct
val b = colToRealString b
val x = String.concat ["(((x + ", x, ") - halfWidth) / halfWidth)"]
val y = String.concat ["(~(y + ", y, ") - halfHeight) / halfHeight)"]
val y = String.concat ["((~(y + ", y, ") - halfHeight) / halfHeight)"]
val ex = String.concat
[ "((((("
@@ -570,7 +570,7 @@ struct
val bintree = merge (qtree, squares)
val coords = BinTree.foldr (toExportStringFolder, bintree, [])
val coords = String.concatWith "," coords
val coords = String.concatWith ",\n" coords
val header = String.concat
[ "structure AAA = \nstruct\n"
@@ -582,7 +582,7 @@ struct
, " #[\n"
]
val footer = String.concat [" ]\n", " end\n", "end\n"]
val footer = String.concat ["\n ]\n", " end\n", "end\n"]
in
String.concat [header, coords, footer]
end

View File

@@ -12,41 +12,6 @@ struct
val filename = "green.dsc"
val exportFilename = "green.sml"
fun ndcToLerpX num =
let
val num = (num + 1.0) / 2.0
val num = Real32.toString num
val num =
(* Problem: It seems that Real32.toString may sometimes return a string
* that is recognised as an integer, like "1" instead of "1.0".
* If that happens, we just add a ".0" to the end
* so it's recognised as a real. *)
if String.isSubstring "." num then num
else num ^ ".0"
in
" (((startX * (1.0 - " ^ num ^ ")) + (endX * " ^ num
^ ")) / windowWidth) - 1.0"
end
fun ndcToLerpY num =
let
val num = (num + 1.0) / 2.0
val num = Real32.toString num
val num = if String.isSubstring "." num then num else num ^ ".0"
in
" (((startY * (1.0 - " ^ num ^ ")) + (endY * " ^ num
^ ")) / windowHeight) - 1.0"
end
fun colToString col =
let val col = Real32.toString col
in if String.isSubstring "." col then col else col ^ ".0"
end
fun exportSquares squares = ()
fun parse (io, acc) = ()
fun loadIO (io, str) =
case TextIO.inputLine io of
SOME line => loadIO (io, str ^ line)
@@ -76,6 +41,14 @@ struct
TextIO.closeOut io
end
fun exportSquares squaresString =
let
val io = TextIO.openOut exportFilename
val () = TextIO.output (io, squaresString)
in
TextIO.closeOut io
end
fun getDirList (dir, acc, rootPath) =
case OS.FileSys.readDir dir of
SOME path =>
@@ -112,7 +85,7 @@ struct
case Mailbox.recv fileMailbox of
SAVE_SQUARES str => saveSquares str
| LOAD_SQUARES => loadSquares (filename, inputMailbox)
| EXPORT_SQUARES triangles => exportSquares triangles
| EXPORT_SQUARES str => exportSquares str
| LOAD_FILES path => loadFiles (path, inputMailbox)
| SELECT_PATH path => selectPath (path, inputMailbox)
in