4 Replies - 1200 Views - Last Post: 03 July 2013 - 09:02 AM Rate Topic: -----

#1 Ann1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-November 12

Count Vowels in A list-Prolog

Posted 25 June 2013 - 05:07 AM

I'm new to prolog ,When I used the code below,I get the output as false
cvowel([],0).
vowel([a],Counter):-Counter is 1.
vowel([e],Counter):-Counter is 1.
vowel([i],Counter):-Counter is 1.
vowel([o],Counter):-Counter is 1.
vowel([u],Counter):-Counter is 1.
vowel([_];[],Counter):-Counter is 0.
cvowel([H|T],Counter1):-cvowel(T,Count),vowel(H,Counter),Count is Count

+Counter,Counter1 is Counter1+Count.




Is This A Good Question/Topic? 0
  • +

Replies To: Count Vowels in A list-Prolog

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1327
  • View blog
  • Posts: 4,552
  • Joined: 19-February 09

Re: Count Vowels in A list-Prolog

Posted 26 June 2013 - 01:14 PM

You are passing the head of the list to the vowel predicate, H is an element of a list.

vowel(H,Counter)



So you don't need a list:

vowel(a,Counter):-Counter is 1.

or

vowel(a, 1).


Was This Post Helpful? 1
  • +
  • -

#3 Ann1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-November 12

Re: Count Vowels in A list-Prolog

Posted 02 July 2013 - 09:11 AM

then to hold a one value we don't need to put []
	vowel(a,Counter):-Counter is 1.


Was This Post Helpful? 0
  • +
  • -

#4 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1327
  • View blog
  • Posts: 4,552
  • Joined: 19-February 09

Re: Count Vowels in A list-Prolog

Posted 02 July 2013 - 01:42 PM

View PostAnn1, on 02 July 2013 - 05:11 PM, said:

then to hold a one value we don't need to put []


You are correct, the square brackets are used for lists and an empty list is [].
Was This Post Helpful? 0
  • +
  • -

#5 Ann1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-November 12

Re: Count Vowels in A list-Prolog

Posted 03 July 2013 - 09:02 AM

Thank you.............
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1