ProPall
ProPall

Reputation: 137

Make function check objects in predicate Prolog

I've recently started learning Prolog and I've a question about predicates and functions. How can I write a function which will check if objects in a predicate is in another predicate For instance:

vertex(a).
edge(l,k,-1).
edge(k,l,4).
edge(a,z,-2).
checkEdges(edge(X,Y,_)) :- vertex(X),vertex(Y)

P.S How can I make this function to print a message if elements are not vertices?

Upvotes: 0

Views: 89

Answers (1)

Tomas By
Tomas By

Reputation: 1394

Something like

checkEdges(edge(X,Y,_)) :-
  ( vertex(X), vertex(Y) ->
    true
  ; write('not vertices'),nl ).

?

Upvotes: 0

Related Questions