I have an operator stored in a variable Op and two integers are stored in X and Y. Now, I want to do something like (Z is X Op Y), but this syntax seems not to be correct.
Does anybody know if there is a way to do this in Prolog?
Thanks for your answers
The == operator is similar to equality operator = but with vital difference. If Term1 and Term2 unify, the Term1==Term2 succeeds. For example: ?- likes(A, mary) = likes(prolog, B).
Performing an "or" in Prolog can also be done with the "disjunct" operator or semi-colon: registered(X, Y) :- X = ct101; X = ct102; X = ct103. Save this answer.
=:= expression is meaning of exactly equal. such as in JavaScript you can use === to also see if the type of the variables are same. Basically it's same logic but =:= is used in functional languages as Prolog, Erlang.
notation contains a number of arguments in parenthesis like likes(hary, jack). Any user-defined predicate which has two arguments can be converted into an infix operator as an alternative. In this, we can write the functor between the two arguments, and they have no parenthesis like. hary likes jack.
you can do it by building the predicate using the =.. operator.
try it like:
compute(X,Y,Op,Z) :-
Eq=..[Op, X, Y],
Z is Eq.
An operator is really just like any other functor.
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