kevinlawler / kona

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

Indexing #560

Closed tavmem closed 4 years ago

tavmem commented 4 years ago
K 2.8 2000-10-10 Copyright (C) 1993-2000 Kx Systems
\ for help. \\ to exit.

  a: .+(`a`b;1 2)
  b: .+(`b`c;3 4)
  i: ,`b
  a i
,2
  b i
,3
kona      \ for help. \\ to exit.

  a: .+(`a`b;1 2)
  b: .+(`b`c;3 4)
  i: ,`b
  a i
2
  b i
3
tavmem commented 4 years ago

But, these agree:

K 2.8 2000-10-10 Copyright (C) 1993-2000 Kx Systems 
\ for help. \\ to exit.

  a: .+(`a`b;1 2)
  j:`b
  a j
2
kona      \ for help. \\ to exit.

  a: .+(`a`b;1 2)
  j:`b
  a j
2
tavmem commented 4 years ago

This change:

$ git diff
diff --git a/src/v.c b/src/v.c
index 951be6a..84faaed 100644
--- a/src/v.c
+++ b/src/v.c
@@ -133,7 +133,7 @@ K at_verb(K a, K b) {    //[Internal Function]
     P(5!=at,TE)
     z=newK(0,bn);
     DO(bn, kK(z)[i]=ci(lookup(a,kS(b)[i])))
-    z=collapse(z); }
+    if(bt>0)z=collapse(z); }
   else if(6==bt) {
     if(0>=at)z=ci(a);
     else if(5==at){z=newK(0,an); DO(an, kK(z)[i]=ci(EV(DI(a,i)))) z=collapse(z);} //TODO: untested

yields the result we were seeking:

kona      \ for help. \\ to exit.

  (.((`a;1;);(`b;2;)))(`b)
2
  (.((`a;1;);(`b;2;)))(,`b)
,2

but causes 5 failures:

$ ./k_test
t:0
t:50
t:100
t:150
t:200
t:250

Failed. These are not equal:
3 4 , d:.((`a;1);(`b;2)); d[!d]:3 4
********************************
3 4
--------------------------------
(3;4)

Failed. These are not equal:
3 4 , d:.((`a;1);(`b;2)); .[`d;_n;:;3 4]; d[!d]
********************************
3 4
--------------------------------
(3;4)

Failed. These are not equal:
3 4 , d:.((`a;1);(`b;2)); @[`d;_n;:;3 4]; d[!d]
********************************
3 4
--------------------------------
(3;4)

Failed. These are not equal:
3 4 , d:.((`a;1);(`b;2)); d[]:3 4; d[!d]
********************************
3 4
--------------------------------
(3;4)

t:300
t:350
t:400
t:450
t:500
t:550
t:600
t:650
t:700
t:750
t:800
t:850
t:900
t:950

Failed. These are not equal:
1 2 , a:.((`b;1);(`c;2)); `a[`b`c]
********************************
1 2
--------------------------------
(1;2)

t:1000
t:1050
t:1100
Test pass rate: 0.9954, Total: 1116, Passed: 1078, Skipped: 33, Failed: 5, Time: 0.384359s
fail
kona      \ for help. \\ to exit.
tavmem commented 4 years ago

All of the above 5 failures seem to boil down to this single failure:

K 2.8 2000-10-10 Copyright (C) 1993-2000 Kx Systems 
\ for help. \\ to exit.

  (.((`a;1);(`b;2)))`a`b
1 2
kona      \ for help. \\ to exit.

  (.((`a;1);(`b;2)))`a`b
(1;2)