JohnEarnest / ok

An open-source interpreter for the K5 programming language.
MIT License
587 stars 72 forks source link

question about 0: #21

Closed ngn closed 9 years ago

ngn commented 9 years ago

Is there publicly available doc about what it does in K5? In oK the in-browser 0: fetches a URL. The REPL's 0: reads/writes to stdio but the todo next to it says it should work with files. The manual has no info about it. k.txt just says "0: file r/w(text)". kx's wiki describes the format only in the dyadic case. I'm particularly interested in whether 0: must be able to read from stdin synchronously.

JohnEarnest commented 9 years ago

For the record, the reason IO verbs are not currently documented in the oK manual is that they are modular- the interpreter itself doesn't provide the facilities and any individual frontend like the browser REPL or iKe can supply IO functions that are appropriate. In the case of the browser REPL there is a brief description of the built in IO verbs here in the readme.

There's no official public documentation on the behavior of the real k5 IO verbs aside from k.txt to my knowledge. As with most of the semantics of oK what I know is based on experimentation and the example programs I've been able to find. I'm not really sure k5 can read from stdin at all. 0: reads from files synchronously and apparently if you give it a directory path it gives you a file listing:

je@kbox:~$ echo "2+3" > test.txt
je@kbox:~$ ls
k  off  test.txt
je@kbox:~$ rlwrap ./k
2015.04.05 (c) arthur whitney

 0:"test.txt"
,"2+3"
 * 0:"test.txt"
"2+3"
 .* 0:"test.txt"
5
 .* 0:`
ERROR: rank
.* 0:`
   ^
 0:""
(,"k";"off";"test.txt")

As I described in #11 k5 is presently invite-only and closed-source but it's fairly easy to obtain a copy to play around with if you ask Arthur Whitney. If there's anything else you'd like me to give a try, let me know.

ngn commented 9 years ago

Thanks. The reason I was asking was because I'd like to experiment with a REPL based on Node's libreadline wrapper instead of your workaround for Node's lack of a readlineSync(). The libreadline wrapper emits events for lines typed by the user, but sadly can't do the synchronous read that's required when ok.setIO()'s hook gets called. However, reading from a file or listing a directory should be fine. I've got a copy of k from last year. It doesn't support symbols ("names"?) as args to 0: and it doesn't list dirs, but otherwise works as you showed above.