SWI-Prolog/swipl-devel — pull request #21 by edisonm (2014-10-29 11:01:36+00:00)
Title: FIXED: Expanded meta arguments whith specifiers greater than zero.

Now term_position/4 is always ground, to allow undesirable choicepoints or
verifications for groundness, for instance in 2nd clause of extend_pos/3,
the call to '$append'/3. Generalized extend_pos/2 and moved from dcg.pl
to expand.pl, which is required to do such expansion.

Hi Jan,
Let me give you additional explanations, because I know this change is touching sensitive parts.
Before this change the goal expansion was reaching only the first level of arguments in a meta_predicate, and ignoring those with specifiers greater than zero. For instance, consider the example:

:- module(exge, [a/1]).
:- meta_predicate b(0, 1, 2).
a(X) :-
X="a~n\c
b~n".
a(X) :-
exge:r,
call(r),
call(b(r), c, d(X)),
call(c, d).
a --> b(r).
d([a,b], a, b).
r.
c(d).
b(_, _, _).

In the previous implementation, if I apply a goal expansion over r/0, deep meta calls to r/0 will not be reached, for instance, in call(b(r), c, d(X)).
I also created an auxiliary predicate in case the extra arguments where misplaced, to wrap the call and placing the extra arguments in the right place ('__aux_wrapper_'...). The predicate variand_sha1_ignore_attr/4 creates a hash used as part of the predicate name, and is required due to the presence of attributed variables.
Best Regards,

Edison