I write count the letters in a list,

ERROR: countvowels/2: Arguments are not sufficiently instantiated

I got this error" why is that?
this is the coding I used

countvowels([H|T],Count1):-Count is Count1 + 1,countvowels(T,Count),Count1>1.
Count is Count1 + 1

I think you meant Count1 is Count + 1 here.

PS: As your code is currently written, it counts any item in te given list - not just vowels.

yes first tried to count any value...............
but though I changed I'm still getting that error

Oh, yes, you also need to move that part after the recursive call. Otherwise Count doesn't have a value at that point either.

Lastly you need to remove the Count1 > 1 bit. Otherwise it would produce False when given a list with only one element and thus, due to the recursion, when given any non-empty list.

Still I'm getting the same error,In the terminal I entered the data like this


After making all the changes I mentioned, the code works fine for me. Can you post your current version of the code?

I got it when change the coding like this

countvowels([],Count1):-Count1 is 0.
countvowels([H|T],Count1):-countvowels(T,Count),Count1 is Count + 1.

But when change that like this

countvowels([],Count1):-Count1 is 0.
countvowels([H|T],Count1):-countvowels(T,Count),Count>1,Count1 is Count + 1.

I got the answer as false why is that?

You need to move Count1 is Count + 1 after the recursive call to countvowels. Otherwise Count doesn't have a value yet at that point.

the false message I got when include


Why is that?

Let's say you pass in a list with one element. Then Count will be 0 (because the length of T will be 0). Therefore Count > 1 will be false and since there are no alternatives, the whole thing will be false. The same thing will be true if you pass in two elements (because 1 > 1 is still false) or even if you pass in more elements than that (because eventually you'll recurse down to a list that has less than 2 elements).

the false message I got when include


Why is that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.