14 lines
455 B
Prolog
14 lines
455 B
Prolog
% my_member(Element, List) - checks if Element is in List
|
|
my_member(Element, Element) :- atomic(Element).
|
|
my_member(Element, Compound) :-
|
|
compound(Compound),
|
|
Compound =.. [Head, Tail],
|
|
(Element = Head ; my_member(Element, Tail)).
|
|
|
|
% my_length(List, Length) - finds the my_length of a list
|
|
my_length(Atom, 1) :- atomic(Atom).
|
|
my_length(Compound, N) :-
|
|
compound(Compound),
|
|
Compound =.. [_, Tail],
|
|
my_length(Tail, M),
|
|
N is M + 1.
|