Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- left_plus(Expr, Left) :- left_plus(Expr, 0, Left).
- % Base case: return the left plus expression when the expression is an atomic
- left_plus(Atomic, Acc, Acc + Atomic) :- atomic(Atomic).
- % Recursive case: recurse left-to-right, accumulating atomics into a left plus expression accumulator
- left_plus(Left + Right, Acc, Result) :-
- atomic(Left),
- left_plus(Right, Acc + Left, Result).
- left_plus(Left + Right, Acc, Result) :-
- \+ atomic(Left),
- left_plus(Left, Acc, Acc2),
- left_plus(Right, Acc2, Result).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement