pred(Args). pred(Args) :- goalA, goalB, !, pred(Args). pred(Args) :- goalC, goalD, !, pred(Args).
Normally, I would write a recursive predicate that deals with memory performance, something in accordance with the code snippet above. When using a slice used to attempt to optimize tail call optimization. I recently went through a large prolog code base and found several examples where the reduction actually occurs after a recursive call, and not immediately in front of it. Presumably, this leads to the prevention of tail call optimization, and not to its help.
My question is: can I move a section after a recursive call directly in front of it without affecting the meaning of the program? It is assumed that in each section of the predicate there is a cut in the same relative location.
Now I thought about this a little more, I think the answer is โoptionalโ, but rewrote all the code with a cut before the call and found that the test suite still passes, Iโm also wondering if there could be some other esoteric reason for writing predicates like this. Or is it just bad coding?
source share