Building an Expression Tree in Prolog

后端 未结 2 442
鱼传尺愫
鱼传尺愫 2020-12-02 02:17

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

2条回答
  •  庸人自扰
    2020-12-02 02:33

    I think this should do it, though I'm not familiar with the construct pred1(pred2(...)...) :- ... (my Prolog is very rusty).

    eval(A, A) :- number(A).
    eval(plus(A, B), R) :- eval(A, A_R), eval(B, B_R), R is A_R+B_R.
    

提交回复
热议问题