Visual Prolog: Maximum number of anyflow

﹥>﹥吖頭↗ 提交于 2019-12-11 13:49:32

问题


I get an error message Maximum number of anyflow variants (1000) exceeded when trying to execute this code:

findNegative([], []).
findNegative([Q|V], Y) :-
   Q > 0,
   !,
   findNegative(V, Y).
findNegative([H1|T1], S) :-
   findNegative(T1, [H1|S]).

Same when trying to execute code from this answer: https://stackoverflow.com/a/6671142/4829408


回答1:


Consider the following code:

find_negatives([],        [] ).
find_negatives([E|Es],    Xs ) :- E >= 0, find_negatives(Es, Xs).
find_negatives([E|Es], [E|Xs]) :- E <  0, find_negatives(Es, Xs).

Sample query:

?- find_negatives([1,2,3,-1,-2,-3,0,1,2,0,-1], Xs).
   Xs = [-1,-2,-3,-1]
;  false.


来源:https://stackoverflow.com/questions/34401942/visual-prolog-maximum-number-of-anyflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!