kevinlawler / kona

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

Output disappearing? #622

Closed gitonthescene closed 1 year ago

gitonthescene commented 2 years ago

Trying to solve AoC day12 with Kona and spotting more differences between kona on the command line and with tio which I assume means there's been a regression.

The following code produces no output from the command line, but does with tio:

data:"\n"\1_"
fs-end
he-DX
fs-he
start-DX
pj-DX
end-zg
zg-sl
zg-pj
pj-he
RW-he
fs-DX
pj-RW
zg-RW
start-pj
he-WI
zg-he
pj-fs
start-RW"
data:"\n"\1_"
start-A
start-b
A-c
A-b
b-d
A-end
b-end"
data:d,|:'d:(`$')'"-"\'data

data:data@&~|/{x=data[;y]}.'+(`end`start;!2)
lg:.+(`end,l;1,97>_ic'*:'$:'l:?data[;0])
sn[l]:~lg[l]
mp:.+(`end,?data[;0];(,()),data[;1]@=:data[;0])
f:{:[(#y)=n:y?x;1;(#y)=1+n;1;(#y)=1+n+(n _1_ y)?x]}
p:,,`start
c:{,/{:[`end=*x;:(,x)];n:mp[*x];(n@&lg[n]|(#x)=x?/:n),\:x}'x}
#(c)/p

Narrowing it down a bit something goes wrong during the recursion:

  c
{,/{:[`end=*x;:(,x)];n:mp[*x];(n@&lg[n]|(n(f)\:x)|(#x)=x?/:n),\:x}'x}
  1{,/{:[`end=*x;:(,x)];n:mp[*x];(n@&lg[n]|(n(f)\:x)|(#x)=x?/:n),\:x}'x}/p
(`A `start
 `b `start)
  2{,/{:[`end=*x;:(,x)];n:mp[*x];(n@&lg[n]|(n(f)\:x)|(#x)=x?/:n),\:x}'x}/p

Also, I seem not to be able to use the function c:

  c p
  1(c)/p
  2(c)/p

[EDIT: I ran git bisect on this with the attached file. (suffix changed)]

e90be4eb391fc15998d6871b7117d68a363c6390 is the first bad commit
commit e90be4eb391fc15998d6871b7117d68a363c6390
Author: Tom Szczesny <tavmem@gmail.com>
Date:   Sat Nov 2 14:11:07 2019 -0400

    fix #566 and fix #549: recursions housed in subfunctions

 src/kx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
make: Nothing to be done for `all'.
kona      \ for help. \\ to exit.

  54
"2021-12-06"

day12.k.txt

gitonthescene commented 2 years ago

Here's a different example which works in tio:

  t:10 5 5#(10*5*5) _draw 2
  {&/+x,+x}'t

Further, this doesn't work in tio, but I'm not sure why:

t:10 5 5#(10*5*5) _draw 2
{|/&/+x,+x}'t

This works as a workaround, though:

t:10 5 5#(10*5*5) _draw 2
{|/(&)/+x,+x}'t

FWIW, this was all while trying to get the day 4 problem from AoC2021 to work in kona.

[EDIT: I decided to follow my own advice and run git bisect on this last which seemed more straightforward to test. With the attached file to test, I found the first bad rev]

$ git bisect good; make; ./k bug.k
69bf768555e74059fc21e26f44092a779082517a is the first bad commit
commit 69bf768555e74059fc21e26f44092a779082517a
Author: Tom Szczesny <tom@localhost.localdomain>
Date:   Sun Sep 1 23:37:25 2019 -0400

    fix #521: Recursive call overrides earlier data

 src/kx.c    | 9 +++++++--
 src/tests.c | 3 ++-
 2 files changed, 9 insertions(+), 3 deletions(-)
make: Nothing to be done for `all'.
kona      \ for help. \\ to exit.

  (0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 1 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 1 0 0 0 0 0 0 0 0 0
 0 1 0 0 0 0 0 0 0 1
 0 0 0 0 0 0 0 0 0 0)
$ 

bug.k.txt

I'll run git bisect on the bug in the original post now...

tavmem commented 1 year ago

With the commit that I will make now:

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

  data:"\n"\1_"
>  fs-end
>  he-DX
>  fs-he
>  start-DX
>  pj-DX
>  end-zg
>  zg-sl
>  zg-pj
>  pj-he
>  RW-he
>  fs-DX
>  pj-RW
>  zg-RW
>  start-pj
>  he-WI
>  zg-he
>  pj-fs
>  start-RW"
  data:"\n"\1_"
>  start-A
>  start-b
>  A-c
>  A-b
>  b-d
>  A-end
>  b-end"
  data:d,|:'d:(`$')'"-"\'data

  data:data@&~|/{x=data[;y]}.'+(`end`start;!2)
  lg:.+(`end,l;1,97>_ic'*:'$:'l:?data[;0])
  sn[l]:~lg[l]
  mp:.+(`end,?data[;0];(,()),data[;1]@=:data[;0])
  f:{:[(#y)=n:y?x;1;(#y)=1+n;1;(#y)=1+n+(n _1_ y)?x]}
  p:,,`start
  c:{,/{:[`end=*x;:(,x)];n:mp[*x];(n@&lg[n]|(#x)=x?/:n),\:x}'x}
  #(c)/p
10

  c p
(`A `start
 `b `start)

  1(c)/p
(`A `start
 `b `start)

  2(c)/p
(`c `A `start
 `b `A `start
 `end `A `start
 `d `b `start
 `end `b `start
 `A `b `start)

  t:10 5 5#(10*5*5) _draw 2
    {&/+x,+x}'t
(0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 1 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 1 0 0 0 0 0 0 0 0 0
 0 1 0 0 0 0 0 0 0 1
 0 0 0 0 0 0 0 0 0 0)

  t:10 5 5#(10*5*5) _draw 2
  {|/&/+x,+x}'t
1 1 0 0 1 0 0 1 0 0

  t:10 5 5#(10*5*5) _draw 2
  {|/(&)/+x,+x}'t
0 0 0 0 1 0 1 0 0 0