I have a predicate that takes two arguments in which the first argument can be a compound one and the second argument is always B. I have also defined some new operators like + and &.
pvc(A, B) :- somestuff(A, B).
Here the user may type something like pvc((x+y)&(A+b), B)
.
As a beginner in Prolog, what I want to do is to convert the compound A
to all lowercase and call somestuff
with new AN
. So it shall be somestuff((x+y)&(a+b), B)
.
I tried something like pvc(A, B) :- downcase_atom(A,AN),somestuff(AN, B).
But it doesn't seem like to be the correct way. I will appreciate any help.
So, you will need to induct on the structure of your thing, and the easiest way to do this is with the univ operator
=../2
. First handle your base case, which you did:Now you will take the structure apart and induct on it using univ:
The trick here is simply breaking your compound down into bits you can use, and then recursively calling
downcase_compound/2
on those bits. See it in action: