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!

Increase variable X by 1

Status
Not open for further replies.

Kazzal

Programmer
Nov 6, 2009
10
AU
Is there an increment function. Or is there count function that could be used to count whether something exists in a list of clauses.?
 
To count things in a list, you can use this prototype :
Code:
% count(List_to_test, Object_to_count, Number_of_occurence)

% when list is empty, 0 object
count([], _, 0).

count([H | T], Object, N) :-
	% we test the rest of the list
	count(T, Object, N1),
	% We test if object fits with H
	(   my_test(H, Object) -> N is N1+1; N = N1).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top