Closed ngn closed 9 years ago
Hmm. I'm a little torn- removing support for stdio breaks the circle.k
, tictac.k
and hangman.k
examples, but on the other hand they never would have worked in the real k5. Node support for stdio also seems to be quite flaky and unstable across versions, so going with what the readline module is capable of ought to be a better way to ensure this codebase still works in the future. Overall this does seem like it could be a usability improvement.
Does this handle file arguments? k5 executes scripts and then drops the user into a prompt, and the old oK repl would process the files and immediately quit. I think the latter behavior is more convenient for testing but either is acceptable:
je@kbox:~$ echo "+/2 7 9" > test.k
je@kbox:~$ cat test.k
+/2 7 9
je@kbox:~$ ./k test.k
18
\\
je@kbox:~$
Additionally, could you modify your pull request to remove the aforementioned examples and update the command-line mode section of the readme to reflect the new CLI repl, removing reference to stdio? Feel free to use different/more interesting examples provided they are reasonably short.
I can implement writing to stdout without problems, that would save circle.k
. Reading is the one that causes trouble.
readline is not concerned with cmd line args. They are available as process.argv
, so implementing k's behaviour is possible.
I noticed a problem with setIO()
. I've put read
in slots 0 1 and write
in 2 3 4 5. This is what happens:
expression callback called
` 0: "bb" write
`a 0: "bb" write
`aa 0: "bb" write
"" 0: "bb" read
"a" 0: "bb" write
"aa" 0: "bb" read
Am I doing something wrong?
Sounds like a bug on my end. I'll have a look.
Should be corrected now- the source of the problem appears to have been a parser bug in which IO verbs were being handled as if they were part of a parenthesized subexpression in certain cases, forcing them to parse as their monadic forms. My bad!
Now it can load .k
files passed as command line arguments. I used the readFileSync()
technique from the original repl.js
to implement monadic `0:`` when not running interactively.
Looks great- thank you!
0:
works with files instead of stdiorepl.js
is executable (chmodded and has a#!
)Please reject if you aren't happy with any of the above.