I am having a difficult time to create a parser in prolog that will allow me to do this:
say I have a database of vowels:
I want to create a function called match([vowel], [.....]). The dotted lines means that it's a list of characters that will be tested if they are vowels or not. The function will return true if the entire character list contains one or more vowels found in the database. An example of an complex expression:
will result in:
notice that it returns true three times as vowel can match one or more vowels.. it can match [e]. [e,e] and [e,e,e]. I am having a difficult time coding it... can someone please help me out?
another example to make it much clear:
one other thing to consider is that I will have another patttern as well besides vowel, one of them is called cons1, which matches exactly one consonant.. we can combine both patterns, vowel and cons1. As an example:
match([vowel, cons1], [a,e,e,k]), will return:
that's the part where I am confused at... so far my code is
which works if pattern is only vowel, but if you put vowel and cons1 (i.e. like the example above) it doesn't work.. that's where I need help I think..
prefix_match([vowel|T], [H|_] ) :- vowel(H).
prefix_match([vowel|T], [H|T1] ) :- vowel(H), prefix_match([vowel|T], T1).