This is my first program in prolog, I've been reading about it and just don't seem to grasp a couple core concepts(I think). I'm trying to write a functor that will take two lists and return true only if the first list has more elements. I've gotten a few simple programs to work, but I have hit a roadblock here. I'm trying to call size inside of isLonger and set temp variables to the return of size. This seems like a bad(and incorrect) way of going about this in prolog. I'm getting a:
ERROR: >/2: Arguments are not sufficiently instantiated
% List 1
a([cat, dog, horse]).
b([1, 2, 3, 4]).
c([x, [a, b], y, z]).
c([red, yellow, green, blue]).
% isLonger function
isLonger([],[]).
isLonger(L1,L2) :- A = size(L1,N), B = size(L2,N), A > B.
% size([],N).
size([_|T],N) :- size(T,N1), N is N1+1.
Input:
isLonger([x,y,z], [7,8,9,10]).
A = size(L1,N). That expression attempts to instantiateAto matchsize(L1,N). It doesn't executesizeas a function and return a value. Thesizepredicate never instantiatesN, so the comparison>occurs with uninstantiated variables, which gives the error. Also, there's a built-in predicatelengthyou can use for this purpose. - lurker