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!

prolog accumulator 1

Status
Not open for further replies.

waqas246

Programmer
Feb 17, 2010
2
GB
How can i create a prdicate for doubling every second entry of a list and discarding the others using an accumulator?
e.g
?-double(['g',o,o,g,l,e],T).
T = [o,o,g,g,e,e]
 
If you use an accumulator, your predicate use 2 args for it, the current state of the accumulator and the final state of it.
Generally, if it's a list it's initialized with [].
The final state is unified when you have finished the work.
I can give you the beginning of the code :
Code:
double(['g',o,o,g,l,e],T) :-
  double(['g',o,o,g,l,e], 0, [], T).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top