Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图理解这段代码的用途,但我不知道。你能给我解释一下吗?
co_to(I, I, [I]). co_to(I, L, [I|L]) :- I < K, I1 is I + 1, co_to(I1, K, L).
正如 gusbro 在他的评论中指出的那样,这段代码不起作用。但是如果你把第二个子句的开头改成
co_to(I, K, [I|L]) :- ...
然后它为一个目标生成一个范围从到的数字co_to(X,Y,L)列表,例如:LXY
co_to(X,Y,L)
L
X
Y
?- co_to(5,10,L). L = [5, 6, 7, 8, 9, 10] Yes (0.00s cpu, solution 1, maybe more) No (0.02s cpu)