JohnEarnest/ok

New additions to K5: if, while, and I/O

refi64 opened this issue · 8 comments

Newer versions of K5 seem to have some new additions:

ryan@DevPC-LX:~/stuff/ok$ rlwrap k5
2016.04.20 (c) arthur whitney
 ""0:"Like `0: in older versions of K"
Like `0: in older versions of K""
 0:"" / reads a line
some input
"some input"
 if(1){""0:,"if statements; k2: if[c;s1;s2] k5: if(c){s1;s2}"}
if statements; k2: if[c;s1;s2] k5: if(c){s1;s2}
 if(1)""0:,"but if only 1 statement, s1, then you can omit braces (like in C)"
but if only 1 statement, s1, then you can omit braces (like in C)
 x:1;while(x){""0:,"in loop";x:0}
in loop
 while(0)""0:,"can omit parens here, too"
 "a" in "like _in in k2"
0
 "a" in "abc"
1
 exp 1
2.718282
 sin 1
8.41471e-1
 "permutations";prm 1 2 3
(1 2 3;1 3 2;2 1 3;2 3 1;3 1 2;3 2 1)
 "combinations";cmb 1 2 3
(1 2 3;1 3 2;2 1 3;2 3 1;3 1 2;3 2 1)

There seem to be some other new additions, according to k.txt:

in bin within ss; exp log sin cos; prm cmb

parallel/mapreduce
f':jobs         / across machine
handles 2:jobs  / across cluster

but I'm not sure how the details work, especially about within vs in:

 "abc" in "abcd"
1 1 1
 "abc" within "abcd"
1 0 0
 "xabcy" in "abcd"
0 1 1 1 0
 "xabcy" within "abcd"
0 1 0 0 0

"xabcy" in "abcd" seems to just check if each character in the left is in the right. I guess "xabcy" within "abcd" checks for substrings somehow?

I've actually obtained a copy of k6, and I think oK will be moving toward compatibility (within reason, as always) with that dialect. I'm currently studying k6 and making a list of things that will need to be tweaked- overall it doesn't look like there are too many nasty breaking changes. When I'm done experimenting I'll put together a checklist for the transition.

Wait, is there k6 now? I thought it was still called k5?

Man, this thing moves fast. :O

Apparently Arthur decided he needed to rewrite k5 completely about a year ago to rearchitect some things. The result was naturally k6. From his description it seems k5 is now frozen and k6 is the one under active development.

For reference, the growing list of known changes is here:
https://github.com/JohnEarnest/ok/blob/gh-pages/docs/Fromk5Tok6.md

@JohnEarnest The new bin seems like an indexing operation. Look at the last example:

 0 2 4 6 8 10'-10 0 4 5 6 20
0N 0 8 10 0N 0N

That's the same result as 0 2 4 6 8 10[-10 0 4 5 6 20].

Ah, good catch!

@JohnEarnest The section on each-pair changing is wrong; I think it just now also special-cases ','. Watch:

ryan@DevPC-LX:~/stuff/ok$ rlwrap k6
2016.04.20 (c) arthur whitney
 ,':3 3 2 1 2 2
(,3;3 3;2 3;1 2;2 1;2 2)
 {x,y}':3 3 2 1 2 2
(3 0N;3 3;2 3;1 2;2 1;2 2)
 {x=y}':3 3 2 1 2 2
0 1 0 0 0 1

ryan@DevPC-LX:~/stuff/ok$ 

I think the additions here that I intend to support in oK work correctly-

  • @refi64's last example does the same thing in oK as that k6 example.
  • I don't intend to add traditional control-flow statements, as I find them unaesthetic. (I thought it was a rather bold and exciting move for Arthur to leave them out in k5 originally)
  • I have in/prm/exp/log/sin/cos.
  • bin/within are a bit unclear and probably relate to queries/tables somehow.
  • cmb I will do eventually; it's in my notes.
  • ss, if it works anything like traditional K, is string-search, which is rather complex. At 1010Data I actually implemented a version of K3's _sm in C, so I think I have a good grasp of how this could work. Gonna punt on that for now as well.

Closing this issue.