我有一个数字块:序言:在列表比较数字
num(1).
num(-2).
num(5).
num(50).
num(-3).
num(87).
我应该做的是给定一个数它应该检查这个数字是最小的那个“功能列表“的数字。
例如:
not_smallest(5).
true.
not_smallest(X).
X = 1 ;
X = -2 ;
X = 5 ;
X = 50 ;
X = 87.
我认为是做与数字的上面块列表,并比较给定数量到列表中的所有元素。 但每当我尝试加载特等DOC我得到这个错误:
Syntax error: Operator expected
是我迄今所做的是这样的:
%increments the index of a List
incr(X, X1) :-
X1 is X + 1.
%L-list containing "list" of numbers, N - elements of that "list",
I-index , C-number X is going to be compared to, X- number to compare.
nao_menor(X) :-
findall(N, num(N), L),
num(X),
I is 0,
nth0(I, L, C),
X =< C,
incr(I,I).
“ %'字符指定了一个注释行(不能有换行符),所以你应该在行'I-index ....'的开头加'%'或者把这两行放在一行中 – gusbro
也是你的'nao_menor/1'程序将无法按预期工作。 (例如'incr(I,I)'将始终失败) – gusbro
我刚刚添加了%来指定变量是什么,它不在原始代码中,但是感谢您的支持。 – eXistanCe