Type error: `character_code' expected with prolog

Type error: `character_code' expected with prolog

我是序言新手。我正在编写一个代码,其中包含哥德巴赫猜想问题,我必须列出所有可能的偶数组。我找到了这样的代码:

is_prime(2).
is_prime(3).
is_prime(P) :- integer(P), P > 3, P mod 2 =\= 0, \+ has_factor(P,3).  

has_factor(N,L) :- N mod L =:= 0.
has_factor(N,L) :- L * L < N, L2 is L + 2, has_factor(N,L2).

goldbach(4,[2,2]) :- !.
goldbach(N,L) :-
  N mod 2 =:= 0,
  N > 4,
  goldbach(N,L,3).
goldbach(N,[P,Q],P) :-
  Q is N - P,
  is_prime(Q), P < Q.
goldbach(N,L,P) :-
  P < N,
  next_prime(P,P1),
  goldbach(N,L,P1).



next_prime(P,P1) :- P1 is P + 2, is_prime(P1), !.
next_prime(P,P1) :- P2 is P + 2, next_prime(P2,P1).

但是当我执行程序时,程序成功打印了第一组,但随后出现错误。

1 ?- goldbach(28, L).
L = [5, 23]
ERROR: Type error: `character_code' expected, found `-1' (an integer)
ERROR: In:
ERROR:   [11] char_code(_4206,-1)
ERROR:   [10] '$in_reply'(-1,'?h') at c:/program files/swipl/boot/init.pl:779

不知道这个错误是怎么产生的,上网找资料也没有。有人知道吗?谢谢你的回答。

Prolog 打印出第一个答案后,它会等待您的输入以告知它您是否对更多答案感兴趣。对于第一个近似值,要按的有效键是 ;(分号)或 Spacen 如果你想要更多答案,或者 . (句点)或 Entery 如果你是对更多答案不感兴趣。

您似乎在使用其他意外的键或组合键。如果您尝试键入 ; 但您的键盘没有对应的键,请尝试 Spacen 代替。

通过在每个答案后按 ;,我可以从您发布的代码中成功获得多个答案:

?- goldbach(28, L).
L = [5, 23] ;
L = [11, 17] ;
false.

编辑:由于您在 Windows,After the first answer, Prolog shows the error "char_code/2: Cannot represent due to 'character_code'" 的答案使用 swipl-win.exe 而不是 swipl.exe 也可能有用。