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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Padding the front of a list with N items

Status
Not open for further replies.

WarwickB

Programmer
Oct 12, 2002
2
NZ
Hi,
I am trying to refine an algorithm that otherwise depends on too many calls to list reverse predicate.

I am trying to define a predicate that takes a list and an integer as arguments, and prepends integer number of items at the front of the list. In this case the items are zeros and the list is a list of integers.

make_pad(Zs, N):- N1 is N-1,
make_pad([0|Zs], N1).
make_pad([_], 0).

Is what I have, but it seems to be nesting the list ad infinitum till the list runs out of stack.

As a less important aside, I am using WinXP and SWI Prolog and I can't seem to get the spy function to work.

Any ideas on either problem would be greatly appreciated.

Best
Warwick


 
make_pad(Zs, N):- N > 0,
N1 is N-1,
make_pad([0|Zs], N1).


missing clause (N>0), it works now.
Silly Me.

Nevertheless I am getting an awful lot of insufficiently instantiated arguments I would just LOVE to know at which point in the code its occuring.

Any assistance with debug trace, spy still very much needed.

Thanks
Warwick

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top