This repository has been archived on 2025-09-23. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
2025LogProg-project-GhentPr.../examples/meta/my_list.pl

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.