I am new to Prolog, and have been having some problems figuring out the syntax of the language. I want to create a method which takes 3 arguements of (X,Y,Z).
X is a list of all of the numbers in between Y and Z. I know that the base case should only return Y since Y+1 = Z. Then the recursive should keep incrementing Y until it is equal to Z while putting the numbers into a list.
Since I am new, I wanted to avoid using built-in libraries and predicates.
This is what I am working off of right now.
range(X,Y,Z):-
%If Y + 1 == Z, X is just Y
range(X,Y,Z) :-
Y =< Z,
D is Y+1,
range(X,D,Z).
%use recursion to go from Y to Z, then collect it in X
I realized a bit later that my expected results should look like this:
range(X,1,10) should return [1,2,3,4,5,6,7,8]