Prolog Prefix Expression
问题 I'm able to get the sum from the prefix expression but whenever I add a list within a list the program doesn't run. expr(Z) --> num(Z). expr(Z) --> [+], num(X), expr(Y), {Z is X+Y}. expr(Z) --> [-], num(X), expr(Y), {Z is X-Y}. num(D) --> [D], {number(D)}. calculate(L, M) :- expr(M, L, []). This works: calculate([+, 2, -, 9, 8], X] but calculate([+, 2, [-, 9, 8]], X] gives false. What do I need in order for it to work list inside of list? 回答1: very simple: ... expr(Z) --> [L], {calculate(L, Z