legs(dog,1). legs(spider,8). animal(dog,blackie). animal(dog,spot). animal(spider,charlotte). animal(spider,ralph). countlegs([],Count,FinalCount):- FinalCount = Count. countlegs([AnimalName|RestOfList],Count,FinalCount):- animal(Type, AnimalName), legs(Type,NumLegs), NewCount is Count + NumLegs, countlegs(RestOfList, NewCount, FinalCount).