I wanto to translate expressions like X = a(b(c(d))) in [a, b, c, d].
I guess i have to iterate/recurse the operator =.., but i don’t know how. I tried
flatten([], []).
flatten(Exp, X) :- Exp=..[H,T], flatten(T, Y), X is append([H], Y).
but it does not seem to work.
Can someone help me?
flatten/2 is a built in usually, while is/2 introduces arithmetic evaluation. Thus your Prolog should warn you about these problems in your code.
If you are limiting the expression to unary terms, the code should be simplified (note I renamed the procedure):
test:
You should try to understand why I swapped the base/recursive case, and the role of the
!(also known as cut).