0

I obtain a specific list using findall, and then want to count the number of elements in it.

i.e.

huntingbreeds(List) :-
   findall(Breedname, breed(Breedname,_,hunting), List).

This returns a need list of hunting dogs from my database [beagle, basset].

But now if i try count it using my new predicate:

list_length([] , 0 ).
list_length([_|Xs] , L ) :- 
        list_length(Xs,N) , 
        L is N+1 .

with my query ?- list_length(huntingbreeds(List), Count).

This just returns false.

I thought I may need to use arg i.e.

?- list_length(arg(1,huntingbreeds(List),L), Count).

but again it returns false. Anyone know how i can get the list size? I know the function list_length works as if i give it:

?- list_length([1,2,3], Count).

I get Count = 3.

But just don't know how to pass it my list from the find result. I have tried putting the full findall statement in place of the huntingbreeds(List) but that still does nothing.

halfer
  • 19,824
  • 17
  • 99
  • 186
ildsarria
  • 281
  • 3
  • 10

1 Answers1

1

You could try:

huntingbreeds(List),list_length(List, Count).
coder
  • 12,832
  • 5
  • 39
  • 53
  • Thanks for the suggestion, but I have to create that list_length predicate with the 2 arguments: list_length(List, count), but your comment helped as I created it like this: List_And_Count(L,Count) :- huntingbreeds(L),list_length(L, Count). – ildsarria Jul 09 '17 at 18:40