Prolog Bubblesort未实例化参数

Prolog Bubblesort未实例化参数,prolog,bubble-sort,Prolog,Bubble Sort,我正在用prolog编写一个bubblesort算法。以下是我到目前为止的情况: bubblesort([],SortedList). bubblesort([X,Y|List], [Y,X|SortedList]) :- X>Y, bubblesort(List, SortedList). bubblesort([N|List], [N|SortedList]) :- bubblesort(List, SortedList). bubble(List, SortedList) :- b

我正在用prolog编写一个bubblesort算法。以下是我到目前为止的情况:

bubblesort([],SortedList).
bubblesort([X,Y|List], [Y,X|SortedList]) :- X>Y, bubblesort(List, SortedList).
bubblesort([N|List], [N|SortedList]) :- bubblesort(List, SortedList).

bubble(List, SortedList) :- bubblesort(List, Sorted),
                         ( check(Sorted)
                         -> SortedList=Sorted
                         ; bubble(Sorted, SortedList) ).
check([]).
check([X,Y|SortedList]) :- X<Y, check(SortedList).
第一次排序时,它工作正常。但是,当它尝试对第一个结果进行排序时,会出现以下错误:

猭ERROR: >/2: Arguments are not sufficiently instantiated
   Exception: (21) bubblesort([32|_G3208], _G3265) ? creep
   Exception: (19) bubblesort([707, -99, 20, 32|_G3208], _G3256) ? creep
   Exception: (17) bubblesort([54, 19, 43, 707, -99, 20, 32|_G3208], _G3247) ? creep
   Exception: (15) bubblesort([79, -67, 45, 54, 19, 43, 707, -99|...], _G3238) ? creep
   Exception: (14) bubblesort([55, -32, 79, -67, 45, 54, 19, 43|...], _G3232) ? creep
   Exception: (13) bubblesort([10101, -98, 55, -32, 79, -67, 45, 54|...], _G3226) ? creep
   Exception: (10) bubblesort([11, 6, 8, 61, 10101, -98, 55, -32|...], _G3214) ? creep
   Exception: (9) bubblesort([2, -4, 11, 6, 8, 61, 10101, -98|...], _G3309) ? creep
跟踪程序显示,当进行此调用时:

Call: (21) bubblesort([32|_G5214], _G5271) ? creep
Call: (22) 32>_G5273 ? creep
出现错误消息。我不明白这个调用是如何进行的,因为我的列表中不应该有未经证实的值。我做错了什么

编辑: 我稍微修改了代码:

bubblesort([],[]).
bubblesort([X,Y|List], [Y,X|SortedList]) :- X>Y, bubblesort(List, SortedList).
bubblesort([N|List], [N|SortedList]) :- bubblesort(List, SortedList).

bubble(List, SortedList) :- bubblesort(List, Sorted),
                         ( check(Sorted)
                         -> SortedList=Sorted
                         ; bubble(Sorted, SortedList) ).
check([]).
check([X,Y|SortedList]) :- X<Y, check(SortedList).
bubblesort([],[])。
bubblesort([X,Y | List],[Y,X | SortedList]):-X>Y,bubblesort(List,SortedList)。
bubblesort([N | List],[N | SortedList]):-bubblesort(List,SortedList)。
气泡(列表,排序列表):-bubblesort(列表,排序),
(检查(已排序)
->排序列表=已排序
;气泡(已排序,已排序列表))。
检查([])。

检查([X,Y | SortedList]):-X这是最终代码。请参见上文,了解我是如何回答自己的问题的:

bubblesort([],[]).
bubblesort([X],[X]).
bubblesort([X,Y|List], [Y,X|SortedList]) :- X>Y, bubblesort(List, SortedList).
bubblesort([N|List], [N|SortedList]) :- bubblesort(List, SortedList).

bubble(List, SortedList) :- bubblesort(List, Sorted),
                         ( check(Sorted)
                         -> SortedList=Sorted
                         ; bubble(Sorted, SortedList) ).
check([]).
check([_]).
check([X,Y|SortedList]) :- X<Y, check([Y|SortedList]).
bubblesort([],[])。
气泡排序([X],[X])。
bubblesort([X,Y | List],[Y,X | SortedList]):-X>Y,bubblesort(List,SortedList)。
bubblesort([N | List],[N | SortedList]):-bubblesort(List,SortedList)。
气泡(列表,排序列表):-bubblesort(列表,排序),
(检查(已排序)
->排序列表=已排序
;气泡(已排序,已排序列表))。
检查([])。
检查([[uU])。
检查([X,Y |分类列表]):-X
check([]).
check([_]).
check([X,Y|SortedList]) :- X<Y, check([Y|SortedList]).
bubblesort([],[]).
bubblesort([X],[X]).
bubblesort([X,Y|List], [Y,X|SortedList]) :- X>Y, bubblesort(List, SortedList).
bubblesort([N|List], [N|SortedList]) :- bubblesort(List, SortedList).

bubble(List, SortedList) :- bubblesort(List, Sorted),
                         ( check(Sorted)
                         -> SortedList=Sorted
                         ; bubble(Sorted, SortedList) ).
check([]).
check([_]).
check([X,Y|SortedList]) :- X<Y, check([Y|SortedList]).