Hi Prologers!
I am quite new to prolog, learning just for fun. I kind of get how it works, but I just found an issue I cannot figure out myself.
The following program runs without problem (based on compress that also runs ok).
compressifpossible(X, [X|Xs], Zs) :- compress([1,X], [X|Xs], Zs).
compressifpossible([Count,X], [X|Xs], Zs) :- compress([Count,X], [X|Xs], Zs).
But with the following version of it (which I would assume to be equivalent):
compressifpossible(X, [X|Xs], Zs) :- compress([1,X], [X|Xs], Zs).
compressifpossible([Count,X], [X|Xs], Zs) :- Count > 1, compress([Count,X], [X|Xs], Zs).
I get the error "arguments are not sufficiently instantiated". (The only difference is that I add the restriction "Count > 1").
If I run these 2 versions of the program, asking the following question:
compress(X, [a,a,a,b,b,c,d,d]).
-> The first one returns the correct result
X=[[3,a],[2,b],c,[2,d]).
-> The second one complains "arguments are not sufficiently instantiated"
Why is adding "Count > 1," causing the "arguments are not sufficiently instantiated"?
Thanks!
B.
I am quite new to prolog, learning just for fun. I kind of get how it works, but I just found an issue I cannot figure out myself.
The following program runs without problem (based on compress that also runs ok).
compressifpossible(X, [X|Xs], Zs) :- compress([1,X], [X|Xs], Zs).
compressifpossible([Count,X], [X|Xs], Zs) :- compress([Count,X], [X|Xs], Zs).
But with the following version of it (which I would assume to be equivalent):
compressifpossible(X, [X|Xs], Zs) :- compress([1,X], [X|Xs], Zs).
compressifpossible([Count,X], [X|Xs], Zs) :- Count > 1, compress([Count,X], [X|Xs], Zs).
I get the error "arguments are not sufficiently instantiated". (The only difference is that I add the restriction "Count > 1").
If I run these 2 versions of the program, asking the following question:
compress(X, [a,a,a,b,b,c,d,d]).
-> The first one returns the correct result
X=[[3,a],[2,b],c,[2,d]).
-> The second one complains "arguments are not sufficiently instantiated"
Why is adding "Count > 1," causing the "arguments are not sufficiently instantiated"?
Thanks!
B.