JohnEarnest / ok

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

+ doesn't flip dicts and ~ doesn't compare them properly #39

Closed ngn closed 4 years ago

ngn commented 8 years ago
 d:[a:0 1;b:2 3]
[a:0 1;b:2 3]
 +d / expected: ([a:0;b:2];[a:1;b:3])
[a:0 1;b:2 3]
 d~+d / expected: 0
1
 d~[a:0 1;b:2 3] / expected: 1
0
JohnEarnest commented 8 years ago

In k5, the flip of a dictionary seems to be a bit of a special case that I'm still looking into. It seems that dictionary transposes may be treated as a special type:

 d:[a:0 1;b:2 3]
 +d
+[a:0 1;b:2 3]
 @[a:0 1]
@[0 1]
 @:[a:0 1]
99
 @:+[a:0 1]
98
 @:(+)
107
 @:(+:)
106

Dictionary comparison with match is a separate and clearer issue- that one should be easier to fix. In oK:

  [a:0 1]~[a:0 1]
0

In k5:

  [a:0 1]~[a:0 1]
1b
ngn commented 8 years ago

I'm puzzled by this bit:

 @[a:0 1]
@[0 1]

The result looks like a curried @ (a "projection"). So k5 considers @[a:0 1] an M-expression with assignment inside the brackets? Then how come +[a:0 1;b:2 3] isn't equivalent to (a:0 1)+(b:2 3)? It must be a special case, like $[if;then;else].

JohnEarnest commented 8 years ago

Dictionary literals result in some subtle syntactic ambiguity with indexing. It's still pretty hard to tell how much of k5's behavior in some corner cases is intentional and how much is a bug or unintended consequence of other features.

JohnEarnest commented 4 years ago

I understand the semantics of "flipping" a dictionary now. This is how you would create a "table" in k6. oK does not support tables (or key-tables) yet, so +d is, intentionally, an identity operation. Closing.