kevinlawler / kona

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

Crash trying to reproduce Sudoku solver #613

Closed gitonthescene closed 1 year ago

gitonthescene commented 2 years ago

This sudoku solver is not written in k3 but I was trying to gather what it does and trying to reproduce in kona. Along the way I typed this (likely illegal) code which crashes consistently: (p:'+:9#'!9)%3.

gitonthescene commented 2 years ago

FWIW, I think the first line of the solver is meant to produce the following, but I can't make much sense out of flip scan. I guess it means collect each flip, i.e. no flip and then flip, but I don't think this is expressible in k3.

p:+{(=x)@x}'(c;r;{y+3*x}/'+(r;c)%3;r:,/p;c:,/+p:(9#'!9))

FWIW, the second line parses but runs into a stack error, which might not be surprising.

  f:{:[&/x;,x;,/_f'@[x;i;:;]'&27=x[,/p i:x?0]?!10]}
  t:.:'"200370009009200007001004002050000800008000900006000040900100500800007600400089001"
  f t
stack error
tavmem commented 2 years ago

(p:'+:9#'!9)%3 is a syntax error in k2.8:

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

  (p:'+:9#'!9)%3
syntax error
(p:'+:9#'!9)%3
  ^
parse error
tavmem commented 2 years ago

The "stack error" does not occur in k2.8:

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

  f:{:[&/x;,x;,/_f'@[x;i;:;]'&27=x[,/p i:x?0]?!10]}
  t:.:'"200370009009200007001004002050000800008000900006000040900100500800007600400089001"
  f t
()

This problem is different from the "crash" you identified, and is probably best tracked as a separate "issue". It's an "enhancement" issue, rather than a "crash".

tavmem commented 1 year ago

Somewhat interesting: In kona, this is a syntax error

  '+:9#'!9
syntax error
> 

but assigning the result is a seg fault

  p:'+:9#'!9

Segmentation fault (core dumped)

and putting the expression in parenthesis before assignment yields a parse error

  p:('+:9#'!9)
parse error
>
gitonthescene commented 1 year ago

FWIW, I now get that flip scan is supposed to produce the pair of the original and its transpose. My K is much better than it was when I posted this issue.