Closed bakul closed 4 years ago
I agree with your observations on the behavior differences between k2.8 and kona.
However, I don't see any documentation of "converge" in the K 2.0 reference manual.
The index has the following entries for \
\
Abort 171
command 198, 200
Scan 138
Scan Dyad 137
Stop / Trace 175
None of the pages listed appear to address the the "converge" capability.
Was this a new feature introduced after K 2.0? ... or an undocumented feature of k?
Well ... whether documented or not ... Shakti k (aka k7) responds in a manner similar to k2.8
$ rlwrap -n ./k
2019-05-24 16:37:43 4core 1gb avx2 © shakti l2.0 test
(1 2 1)\1
1 2
(1 2 1)\0
ws
$
Still, it would still be good to have an better understanding of what "converge" is attempting to do, in a more general case than two examples (one of which fails).
BTW: the index in the K 2.0 reference manual is not complete. At a minimum, it leaves out "scan monad"
\
Abort 171
command 198, 200
Scan 138
Scan Dyad 137
Stop / Trace 175
Scan Monad 139
A second omission in the K 2.0 Reference Manual index ("Each Left"):
\
Abort 171
command 198, 200
Each Left 125
Scan 138
Scan Dyad 137
Scan Monad 139
Stop / Trace 175
It is basically scan monad, documented in the reference manual. It is related to over monad similar to how scan dyad is related to over dyad_. The over monad iterates, while the scan monad traces the iteration.
kona handles the over monad correctly for list/x
and f/x
and the scan monad for f\x
but not for list\x
.
Incidentally typing \'
to k3 shows you the CONVERGE operation:
...
m/ CONVERGE n m/ DO b m/ WHILE
m\ CONVERGE n m\ DO b m\ WHILE
...
where m
is any monad, including a list.
Thanks !! I think my problem was conceptualizing a list as completely different from a monadic function.
Scan Monad is defined as being one of the following
f\ x
n f\ x
b f\ x
where f must be a monadic function.
To (hopefully) demonstrate the problem a bit clearer using the sample monadic function from the Scan Monad section (page 139) of the K 2.0 reference manual:
kona \ for help. \\ to exit.
f:{:[x ! 2; x; _ x % 2]}
f/ 12
3
f\ 12
12 6 3
Kona works fine using the function. Kona should work exactly the same using the list that is equivalent to that function over the relevant function domain:
f'!13
0 1 1 3 2 5 3 7 4 9 5 11 6
0 1 1 3 2 5 3 7 4 9 5 11 6/ 12
3
0 1 1 3 2 5 3 7 4 9 5 11 6\ 12
12
but it does not.
This is a regression. It was broken by commit a5a1903c95d8d4b79fe2941864b403cb25387d80 on Feb 3, 2015.
Removing the Feb 3, 2015 "fix" is easy ... but then 6 tests fail:
Failed. These are not equal:
2 , m:3 4#!12; m\2
********************************
2
--------------------------------
Failed. These are not equal:
6 , m:3 4#!12; 1 m\2
********************************
6
--------------------------------
(2
8 9 10 11)
Failed. These are not equal:
(,"alpha") , " "\"alpha"
********************************
,"alpha"
--------------------------------
Failed. These are not equal:
("";"lph";"") , "a"\"alpha"
********************************
(""
"lph"
"")
--------------------------------
Failed. These are not equal:
(,"a";"pha") , "l"\"alpha"
********************************
(,"a"
"pha")
--------------------------------
Failed. These are not equal:
("";"";"";"") , "a"\"aaa"
********************************
(""
""
""
"")
--------------------------------
The Feb 3, 2015 "fix" forced these cases to use "scanDyad" instead of "scanMonad". While that worked for these 6 cases, there does not appear to be a Dyad in any of the 6.
What corresponds to the "f" argument is either a matrix (list of lists), or an atom ... so, all 6 seem to be "scanMonad" cases.
This indicates that there is something wrong with "scanMonad" that should be fixed.
The commit above is not what I consider an optimal fix in that it still uses "scanDyad" to process some commands where "f" is clealy a monad. However, all tests pass and it's an easy fix.
kona \ for help. \\ to exit
(1 2 1)\1
1 2
0 1 1 3 2 5 3 7 4 9 5 11 6\ 12
12 6 3
(1 2 1)\0
In the final case, Kona runs out of space and freezes. Not elegant, but Kona is no longer responding with an incorrect result.
(1 2 1)\1
yields1 2
in k but1
in kona(1 2 1)\0
runs out of eval size limit in k but just yields0
in kona