Define a Prolog predicate makelist/3 such that makelist(Start, End, List) is true if
List is a list of all integers from the integer Start to the integer End. For example:
makelist(3, 7, [3, 4, 5, 6, 7]) should be true.
Can't understand why my code doesn't work
makelist(H, L, _) :-
L is H+1.
makelist(H, L, List) :-
append([], [H], List), H1 is H+1.
makelist(H1, L, List) :-
append(List, [H1], List1), last(List1, R),
R \= L+1, makelist(N, L, List1), N is H1+1.
makelist(3, 4, [x,y,z])for example since4 is 3+1would succeed.[x,y,z]could literally be any list, and it would succeed. In your second clause,H1is evaluated asH + 1butH1is never used. Your third clauses useslast/2. Where and how is it defined? - lurkerlast/2is predefined in SWI- Prolog. I didn't know that either - ShevliaskovicHandLare the same. So your base case predicate might be,makelist(H, H, ?)(what would?look like?). And then think about how you would get to the base case recursively from the general case. - lurkerlast/2predicate is a library predicate in SWI-Prolog, not a built-in predicate. It's defined in thelistsmodule which, by default, is auto-loaded when a call to one of its predicate is found. - Paulo Moura