Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

N > 1 -> Arguments are not sufficiently instantiated

Status
Not open for further replies.

bleikur

Programmer
Oct 9, 2010
4
NO
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 need the code of compress to explain : how is called compressifpossible.
I think that Count is unified at the end of the process of compress([Count,X], [X|Xs], Zs) so you can't test it before its call.
 
Thanks, joel76 :)

And sorry for my bad explanation. Compressifpossible calls compress, but compressifpossible is called by:

encode2([],[]).
encode2([X|Xs], [Y|Ys]) :- compressifpossible(X, [Y|Ys], Zs), encode2(Xs, Zs).

So actually I meant that I call it by asking encode2(..) and not compress(..) as I said.

Anyway I think it is right what you say about the unification at the end. If I add that restriction after the call to compress (instead of before the call) then it works fine. :)

Maaany thanks :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top