A very simple concept in the prologue - this pattern matching
there are many tutorials explaining this, for example this one you can also check the first and second chapters.
, , - , :
X, .
.
X if
has_attribute(X):-
belongs_db(X),
is_even(X).
X , a (b (X))
belongs_in_db(X):-
a(b(X)).
X 2 0:
is_even(X):-
0 =:= X mod 2.
has_attribute (X), , X.
, X. , findall/3
X, , ,
findall(X,has_attribute(X),List).
X ,
, writeln/1:
writeln(List)
, :
run:-
findall(X,has_attribute(X),List),
writeln(List).
has_attribute(X):-
a(b(X),
0 =:= X mod 2.
, .
,
my_print_list([]).
, , :
my_print_list([Head|Tail]):-
writeln(Head),
my_print_list(Tail).