?- t(X).
X = [] ;
X = [1] ;
X = [1, 1] ;
X = [1, 1, 1] .
This is because all predicates are known and the yall library will use goal expansion to generate a helper predicate which causes the variable sharing to disappear.
The dynamically called version doesn’t do this. I’m not sure whether or not it would be possible to make the behavior fully consistent.
The alternative is the add on lambda, which AFAIK always uses dynamic calling while I think it does examples like this correctly. The price is an even more ugly syntax and pretty high runtime overhead.
All in all, Lambdas seem to fit Prolog poorly. They have been discussed for decades. At some point library(lambda) and library(yall) got some popularity, notably for people with a functional programming background. I still prefer the solution below. Ok, it needs one more line. Often you can find a sensible name for the helper which makes your code more readable.