tizoc / shen-scheme

Shen/Scheme implementation
Other
100 stars 8 forks source link

10000 is not a valid index for #(shen.print-prolog-vector 10000 #24

Open lbuczkow opened 2 years ago

lbuczkow commented 2 years ago

I have been playing with Prolog in shen-scheme-v0.27.1-macOS. The encountered issue seems to be related to this line in make.shen:

(set *maximum-print-sequence-size* 10000)

But why does it occur? The number of solutions returned by the query is far below the limit.

Shen, www.shenlanguage.org, copyright (C) 2010-2022, Mark Tarver
version: S33.1.2, language: Scheme, platform: chez-scheme 9.5.8
port 0.27.1, ported by Bruno Deferrari

(0-) (defprolog queens
  N Queens <-- (len Queens N) (place_queens N Queens _ _);)

(defprolog place_queens 
  0 _ _ _ <-- !;
  N Cs Us [_|Ds] <-- (is M (- N 1)) (place_queens M Cs [_|Us] Ds) (place_queen N Cs Us Ds);)

(defprolog place_queen 
  N [N| _] [N| _] [N| _] <-- ;
  N [_|Cs] [_|Us] [_|Ds] <-- (place_queen N Cs Us Ds);)

(defprolog len
  [] 0 <-- ;
  [_|L] N <-- (len L M) (is N (+ 1 M));)

(prolog? (queens 8 Queens) (return Queens))

(prolog? (findall Queens (queens 8 Queens) Res))

(fn queens)

(1-) (fn place_queens)

(2-) (fn place_queen)

(3-) (fn len)

(4-) [1 7 5 8 2 4 6 3]

(5-) 
10000 is not a valid index for #(shen.print-prolog-vector 10000 (#(shen.pvar 7) . #(shen.pvar 8)) shen.-null- ((3 6 4 2 8 5 7 1) 
(3 5 2 8 6 4 7 1) (5 2 4 7 3 8 6 1) (4 2 7 3 6 8 5 1) (4 7 3 8 2 5 1 6) (6 3 7 2 8 5 1 4) (6 3 7 2 4 8 1 5) (6 4 2 8 5 7 1 3) 
(3 7 2 8 6 4 1 5) (5 2 4 6 8 3 1 7) (4 2 7 3 6 8 1 5) (2 7 3 6 8 5 1 4) (5 3 8 4 7 1 6 2) (4 6 8 2 7 1 3 5) (4 7 5 2 6 1 3 8) 
(7 3 8 2 5 1 6 4) (3 6 8 2 4 1 7 5) (5 7 2 4 8 1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(8 3 1 6 2 5 7 4) 
(5 3 1 7 2 8 6 4) (2 6 1 7 4 8 3 5) (4 1 5 8 6 3 7 2) (5 1 8 6 3 7 2 4) (7 1 3 8 6 4 2 5) (5 1 4 6 8 2 7 3) (3 1 7 5 8 2 4 6) 
(5 1 8 4 2 7 3 6) (4 1 5 8 2 7 3 6) (6 1 5 2 8 3 7 4) (1 5 8 6 3 7 2 4) (1 6 8 3 7 4 2 5) (1 7 4 6 8 2 5 3) (1 7 5 8 2 4 6 3)) 
shen.-null- shen.-null- shen.-null- (#(shen.pvar 10) . #(shen.pvar 11)) shen.-null- shen.-null- (#(shen.pvar 13) . 
#(shen.pvar 14)) shen.-null- shen.-null- (#(shen.pvar 16) . #(shen.pvar 17)) shen.-null- shen.-null- (#(shen.pvar 19) . 
#(shen.pvar 20)) shen.-null- shen.-null- (#(shen.pvar 22) . #(shen.pvar 23)) shen.-null- shen.-null- (#(shen.pvar 25) . 
#(shen.pvar 26)) shen.-null- shen.-null- (#(shen.pvar 28) . #(shen.pvar 29)) shen.-null- shen.-null- (#(shen.pvar 31) . 
#(shen.pvar 32)) shen.-null- shen.-null- (#(shen.pvar 34) 
...  
#(shen.pvar 9995)) shen.-null- shen.-null- (#(shen.pvar 9997) . #(shen.pvar 9998)) 
shen.-null- shen.-null- shen.-null- shen.-null-) 
tizoc commented 2 years ago

@lbuczkow hello! The issue is that you are running out of space in the prolog vector (initialized here). You can increase the size by calling the prolog-memory function: (prolog-memory 1e5)

But even when I do that, I get the same failure when running your code (it just takes longer, and it fails when trying to access index 100000), so it seems the code never terminates?