(This is a followup to that question).
How to write lead1(Xs,Ys)
which is true, iff Ys
is a suffix of Xs
with all leading s(s(0))
terms removed. Thus instead of removing leading 0
s this question is now about removing leading s(s(0))
s.
Compared to the original question, the difficulty lies here in handling cases of s(X)
and s(s(X))
properly.
Here's a version with if_/3 and =/3:
Queries with a ground first argument succeed deterministically:
If the list consists of a term different from s/1, say
f(_)
the second list is identical to the first:Partially instantiated lists work as well:
The most general query works as well but is listing the answer in an unfair manner:
However, this can be remedied by prefixing a goal length/2: