Prolog Predicate List

Is it possible to define a list consisting of predicates and how can I name predicates.

In addition, is it possible to transfer one predicate to another predicate (for example, to transfer atoms)?

Example:

pre1:- something.
pre2(Predicate1, List):-
    call(Predicate1),
    append([Predicate1], List, R),
    .....
+3
source share
1 answer

You cannot store predicates in a list, but you can store terms (or functors) and call terms as targets.

Here's a predicate that checks if a member has the properties described in the list of functors:

has_properties([], _).
has_properties([P|Ps], X) :-
    Goal =.. [P, X],            % construct goal P(X)
    call(Goal),
    has_properties(Ps, X).

Using:

% is 4 a number, an integer and a foo?
?- has_properties([number, integer, foo], 4).

The answer to this request will depend on your definition foo/1, of course. See explanation=.. if necessary.

: @false =.., Goal =.. [P, X], call(Goal) call(P, X), . , =.., .

+5

Source: https://habr.com/ru/post/1584727/


All Articles