I\'m looking for a way to build an Expression Tree in Prolog. I already did some experiments and came up with the following working code (that will only handle constants and
I think this should do it, though I'm not familiar with the construct pred1(pred2(...)...) :- ... (my Prolog is very rusty).
pred1(pred2(...)...) :- ...
eval(A, A) :- number(A). eval(plus(A, B), R) :- eval(A, A_R), eval(B, B_R), R is A_R+B_R.