Trivial question but I want the program to return a list of the numbers less than or equal to a given number. For example, CountD(4,L)
. should give [4,3,2,1]
. This is what I have so far:
CountD(1,[]).
CountD(Num,List):- [Num|List], CountD(M,List), Num is M+1.
This is also a solution:
Here, the important line is
succ(N0, N)
. This will only succeed for N > 0, and will fail when the second argument is 0 (it will also raise an error if N is not a non-negative integer).When
succ(N0, N)
fails, the second clause will be evaluated. It will only succeed when its arguments are 0 and the empty list.