Let's say I have a list looking like this:
List=[alpha(1,2),beta(3,4),gamma(4,1)]
Ok, so I want to make a certain pattern matching here... I know I can do:
Try=alpha(Y,Z).
Try=alpha(1,2)
Y=1
Z=2
But I would like to do for example:
Try=X(Y,Z)
X=alpha
Y=1
Z=2
...so that I can pass on the data to another predicate:
targetPredicate(Type,Value1,Value2):-
Type=alpha
...
and then do something with it instead of having to make one help predicate for every type I might run into:
helpPredicate(Input):-
Input=alpha(Value1, Value2),
targetPredicateAlt(Value1, Value2).
helpPredicate(Input):-
Input=beta(Value1, Value2),
targetPredicateAlt(Value1, Value2).
helpPredicate(Input):-
Input=gamma(Value1, Value2),
targetPredicateAlt(Value1, Value2).
Is there any way to get around this or am I doomed to use a ton of help predicates?
You can use the univ predicate =../2:
Suppose you have Try=alpha(1,2), then
Try =..[Name, X, Y].
would yield Name = alpha, X = 1, Y = 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With