kevinlawler / kona

Open-source implementation of the K programming language
ISC License
1.36k stars 138 forks source link

nth dimension join bug #539

Closed bakul closed 5 years ago

bakul commented 5 years ago
  x:3 3#!9
  x,''x
((,[0;];,[1;];,[2;])
 (,[3;];,[4;];,[5;])
 (,[6;];,[7;];,[8;]))

This should yield

((0 0
  1 1
  2 2)
 (3 3
  4 4
  5 5)
 (6 6
  7 7
  8 8))
tavmem commented 5 years ago

Unfortunately, this does not appear to be a regression. (Regressions are often easier to fix.) I checked the status of kona using a commit made on June 23, 2011 and got the same result.

tavmem commented 5 years ago

Both of these work:

  (2 2# 1 2 3 4) ,' (2 2# 5 6 7 8)
(1 2 5 6
 3 4 7 8)

  1 2 ,' 5 6
(1 5
 2 6)

Somewhere, the transition between the 2 steps fails:

  (2 2# 1 2 3 4) ,'' (2 2# 5 6 7 8)
((,[5;];,[6;])
 (,[7;];,[8;]))

Will try to find that transition.

tavmem commented 5 years ago

Both of these cases are arguably simpler, but have a similar problem in Kona. Note that (in the 1st case) Kona yields both an incorrect data structure, and incorrect numbers.

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  1 +'' 2 2 # 1 2 3 4
((+[1;];+[2;])
 (+[3;];+[4;]))

   +'' 2 2 # 1 2 3 4
((+[1;];+[2;])
 (+[3;];+[4;]))

Of the above, only 1 case is valid in k2.8

$ rlwrap -n ./k
K 2.8 2000-10-10 Copyright (C) 1993-2000 Kx Systems 
\ for help. \\ to exit.

  1 +'' 2 2 # 1 2 3 4
(2 3
 4 5)

  +'' 2 2 # 1 2 3 4
valence error
+'' 2 2 # 1 2 3 4
^
>  \
bakul commented 5 years ago

The second expression should be +:''2 2#1 2 3 4 to get rid of the valence error and then it works the same way in k and kona.

tavmem commented 5 years ago

After the commit titled: "partial fix for issue 539": These 2 cases work:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  a: 2 2 # 1 2 3 4
  5 +'' a
(6 7
 8 9)

  5 ,'' a
((5 1
  5 2)
 (5 3
  5 4))

This case is still broken (but differently):

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  a: 2 2 # 1 2 3 4
  a ,'' a
((1 2 1
  3 4 2)
 (1 2 3
  3 4 4))
tavmem commented 5 years ago

Another case that still fails, but differently: before the commit "partial fix for issue 539":

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  a:1 2

  a ,' a
(1 1
 2 2)

  a ,'' a
(,[1;];,[2;])

  a ,''' a
(,[1;];,[2;])

After the commit:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  a: 1 2

  a ,' a
(1 1
 2 2)

  a ,'' a
((1 1
  2 1)
 (1 2
  2 2))

  a ,''' a
(,[1;];,[2;])

In k2.8

$ rlwrap -n ./k
K 2.8 2000-10-10 Copyright (C) 1993-2000 Kx Systems 
\ for help. \\ to exit.

  a: 1 2

  a ,' a
(1 1
 2 2)

  a ,'' a
(1 1
 2 2)

  a ,''' a
(1 1
 2 2)
bakul commented 5 years ago

In k 1,1 == 1,'1 == 1,'...'1 == 1 1. In general this is true for any verb. Given x fE y, where f is a dyad and E is one or more ' (that is, each), once x and y become scalars, further each adverbs should be thrown away.

tavmem commented 5 years ago

After commit titled "fix more of issue 539" this works:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  a: 2 2 # 1 2 3 4
  a ,'' a
((1 1
  2 2)
 (3 3
  4 4))

Still need to fix the "throw away" of excessive "each" adverbs

tavmem commented 5 years ago

The case in which a scalar is on the right is also still broken:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  a: 2 2 # 1 2 3 4
  a +'' 5
+[5;]

  a ,'' 5
,[5;]
tavmem commented 5 years ago

After commit "fix: scalar on right (issue 539)", this works:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  a: 2 2 # 1 2 3 4
  a +'' 5
(6 7
 8 9)
tavmem commented 5 years ago

Oops: This is still broken:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  a: 2 2 # 1 2 3 4
  a ,'' 5
(1 2 5
 3 4 5)
tavmem commented 5 years ago

After commit "issue 539: fix scalar on right (with join)", this works:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  a: 2 2 # 1 2 3 4
  a ,'' 5
((1 5
  2 5)
 (3 5
  4 5))
bakul commented 5 years ago

Still not right. Try

a:(1 2;3 4)
a,'''a

This should be identical to a,''a

tavmem commented 5 years ago

I believe that your example is a case where extra "each" instances need to be "thrown away". Another example:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  1 , 2
1 2

  1 ,' 2
1 2

  1 ,'' 2
Segmentation fault (core dumped)
tavmem commented 5 years ago

After the commit "fix 539: some of the extra each examples", both of the examples above work. Leaving this issue open for a while, as there are probably other examples that faill.

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  a:(1 2;3 4)
  a,'''a
((1 1
  2 2)
 (3 3
  4 4))

  1,'2
1 2
  1,''2
1 2
  1,'''2
1 2
tavmem commented 5 years ago

Here's an example that still fails:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  "a","b"
"ab"
  "a",'"b"
"ab"
  "a",''"b"
Segmentation fault (core dumped)
tavmem commented 5 years ago

After commit "fix 539: extend coverage to float, char & symbol" all of these work:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  "a" ,'' "b"
"ab"

  `a ,'' `b
`a `b

  1.1 ,'' 2.2
1.1 2.2