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
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