JohnEarnest / ok

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

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

Closed refi64 closed 4 years ago

refi64 commented 8 years ago

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?

JohnEarnest commented 8 years ago

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.

refi64 commented 8 years ago

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

Man, this thing moves fast. :O

JohnEarnest commented 8 years ago

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.

JohnEarnest commented 8 years ago

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

refi64 commented 8 years ago

@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].

JohnEarnest commented 8 years ago

Ah, good catch!

refi64 commented 8 years ago

@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$ 
JohnEarnest commented 4 years ago

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

Closing this issue.