kevinlawler / kona

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

Resume & distinct primitives #568

Closed tavmem closed 4 years ago

tavmem commented 4 years ago

Resume works if all primitives are distinct:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.
  4 + 3 * 2 - 1
7

  4 + "x" * 2 - 1
type error
4 + "x" * 2 - 1
        ^
>  : 3 * 2 - 1
7

  4 + 3 * "x" - 1
type error
4 + 3 * "x" - 1
            ^
>  : 2 - 1
7

But it sometimes fails if the primitives are not distinctly unique:

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

  4 + 3 + 2 + 1
10

  4 + "x" + 2 + 1
type error
4 + "x" + 2 + 1
at execution instance 2 of "+"
>  : 3 + 2 + 1
10

  4 + 3 + "x" + 1
type error
4 + 3 + "x" + 1
at execution instance 1 of "+"
>  : 2 + 1
7
tavmem commented 4 years ago

After commit noted above:

kona      \ for help. \\ to exit.

  5 + 4 + 3 + 2 + 1
15

  "5" + 4 + 3 + 2 + 1
type error
"5" + 4 + 3 + 2 + 1
at execution instance 4 of "+"
>  :5+4+3+2+1
15

  5 + "4" + 3 + 2 + 1
type error
5 + "4" + 3 + 2 + 1
at execution instance 3 of "+"
>  :4+3+2+1
15

  5 + 4 + "3" + 2 + 1
type error
5 + 4 + "3" + 2 + 1
at execution instance 2 of "+"
>  :3+2+1
15

  5 + 4 + 3 + "2" + 1
type error
5 + 4 + 3 + "2" + 1
at execution instance 1 of "+"
>  :2+1
15

  5 + 4 + 3 + 2 + "1"
type error
5 + 4 + 3 + 2 + "1"
at execution instance 1 of "+"
>  :2+1
15