Prolog. Combining predicates -
i have make predicate/2
takes list of "correct" numbers validation, , function needs validated. numbers in function (represented number(x)
) has same numbers in validation list, become "true".
i have no problem making 2 seperate predicates/1
give correct answer when list "hard-coded" in library, can god of mine not combine these.
i have far:
number(x) :- member(x, [1,2,3,4,5]).
this gives correct result when ask for example and(number(2),number(4))
, says yes, , and(number(2),number(6))
gives no.
but have predicate/2
, takes list first argument. can help/give hint?
predicate(validationlist, function) :- ????
you can use call
predicate:
and(x,y) :- call(x), call(y). or(x,y) :- call(x); call(y). predicate(list, function) :- function =.. [p,x,y], call(p, member(x, list), member(y, list)).
for example:
?- predicate([1,2,3], and(1,3)). true. ?- predicate([1,2,3], and(1,4)). false. ?- predicate([1,2,3], or(1,4)). true. ?- predicate([1,2,3], or(4,5)). false.
Comments
Post a Comment