Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prolog Help Various Rules

Status
Not open for further replies.

DavideBar

Programmer
Jun 12, 2014
1
PT
Hello all! I really need some help of yours :D

I've got all these rules:

Returns all the vowels on a list
Code:
extractvowels([], []).
extractvowels([H|T], R) :- consonant(H), extractvowels(T, R).
extractvowels([H|T],[H|R]) :- \+ consonant(H), extractvowels(T, R).

Flattens a list:
Code:
flatten([],[]).
flatten([A|L],[A|L1]) :- xatom(A), flatten(L,L1).
flatten([A|L],R) :- flatten(A,A1), flatten(L,L1), append(A1,L1,R).

xatom(A) :- atom(A).
xatom(A) :- number(A).

Returns true or false:
Code:
member(X, [X|_]).      
member(X, [_|Tail]) :- member(X, Tail).

How can I type
Code:
extractvowels([s,a,r,a],X).
And get as result this
Code:
X = [a].
?

How can I join the rule
Code:
flatten
with the
Code:
extractvalues
?

And how can I create a rule that is able to remove the duplicates ?

PS: I can't use any of the built-in predicates :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top