This kinda-sorta works:
$ cd share/Formality/
$ git diff
diff --git a/javascript/FormalityToJS.js b/javascript/FormalityToJS.js
index c2dc6a1..2089d39 100644
--- a/javascript/FormalityToJS.js
+++ b/javascript/FormalityToJS.js
@@ -863,6 +863,7 @@ function compile(main, defs, only_expression = false) {
code += " switch (p.query) {\n";
code += " case 'print': console.log(p.param); run(p.then(1)).then(res); break;\n";
code += " case 'get_line': rdl.question('', (line) => run(p.then(line)).then(res)); break;\n";
+ code += " case 'get_args': run(p.then(process.argv)).then(res); break;\n";
code += " }\n";
code += " });\n";
code += " }\n";
$ cd -
/home/bukzor/scratch/formality
$ cat echo.fm
echo.drop(_: String): IO(Unit)
IO.end<Unit>(Unit.new)
echo.print_args(args: String): IO(Unit)
//IO.ask<Unit>("print", List.show<String>(String.show, args),
IO.ask<Unit>("print", args,
echo.drop
)
echo: IO(Unit)
IO.ask<Unit>("get_args", "",
echo.print_args
)
$ fmio echo 1 "2 3"
[
'/home/linuxbrew/.linuxbrew/Cellar/node/14.5.0/bin/node',
'/home/bukzor/scratch/formality/share/node_modules/.bin/fmio',
'echo',
'1',
'2 3'
]
But if I just add a simple String.reverse
to the "args", it becomes clear that the typing is all wrong.
$ cat echo.fm
echo.drop(_: String): IO(Unit)
IO.end<Unit>(Unit.new)
echo.print_args(args: String): IO(Unit)
//IO.ask<Unit>("print", List.show<String>(String.show, args),
IO.ask<Unit>("print", String.reverse(args),
echo.drop
)
echo: IO(Unit)
IO.ask<Unit>("get_args", "",
echo.print_args
)
$ fmio echo 1 "2 3"
(node:20633) UnhandledPromiseRejectionWarning: TypeError: self.charCodeAt is not a function
at eval (eval at _io_ (/home/bukzor/scratch/formality/share/Formality/javascript/bin/lib.js:221:7), <anonymous>:40:272)
at eval (eval at _io_ (/home/bukzor/scratch/formality/share/Formality/javascript/bin/lib.js:221:7), <anonymous>:40:363)
at String$reverse (eval at _io_ (/home/bukzor/scratch/formality/share/Formality/javascript/bin/lib.js:221:7), <anonymous>:42:54)
at Object.echo$print_args [as then] (eval at _io_ (/home/bukzor/scratch/formality/share/Formality/javascript/bin/lib.js:221:7), <anonymous>:46:50)
at eval (eval at _io_ (/home/bukzor/scratch/formality/share/Formality/javascript/bin/lib.js:221:7), <anonymous>:33:34)
at new Promise (<anonymous>)
at run (eval at _io_ (/home/bukzor/scratch/formality/share/Formality/javascript/bin/lib.js:221:7), <anonymous>:29:29)
at Object.$main$ (eval at _io_ (/home/bukzor/scratch/formality/share/Formality/javascript/bin/lib.js:221:7), <anonymous>:49:19)
at eval (eval at _io_ (/home/bukzor/scratch/formality/share/Formality/javascript/bin/lib.js:221:7), <anonymous>:62:25)
at Object._io_ (/home/bukzor/scratch/formality/share/Formality/javascript/bin/lib.js:221:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:20633) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:20633) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.