Reputation: 735
This is my arithmetic inequality expression in prolog:
2*X + 3*Y > 4*Z
I used the unity term manipulator like this:
Expr =.. [Op, Lhs, Rhs]
And now I have Lhs = 2*X + 3*Y, Rhs as 4*Z and Op as >
Everything fine till now.
What I want is to construct a delayed goal using the IC library in Eclipse Prolog for this expression. Example, I want a newly created variable to assigned like this:
Eq = (Lhs #Op Rhs) %meaning, Eq = (2*X + 3*Y #> 4*Z)
Now, since the required inequality (in this case >), is stored in Op, though I use Eq = (Lhs #Op Rhs)
, eclipse is returning error.
How do i create this delayed constraint, when my operator is to be taken from the variable Op? Thank You.
Upvotes: 0
Views: 165
Reputation: 2436
You could use facts to define the relations:
cstr(=,#=).
Or use concat_atom/2
:
concat_atom([#,Op],CstrOp),
E.g.:
?- Eq = (X = 1),
Eq =.. [Op, L, R],
concat_atom([#, Op], CstrOp),
Cstr =.. [CstrOp, L, R],
call(Cstr).
Eq = 1 = 1
X = 1
Op = =
L = 1
R = 1
CstrOp = #=
Cstr = 1 #= 1
Yes (0.00s cpu)
Note that this only works for the basic equality/inequality operators. You cannot add #
to just any operator and expect it to work as a constraint!
Upvotes: 1