maplist/N for N = 0, 1 as a meta predicate

Recently I noticed that following query for maplist/N fails with N = 0,1 :

?- predicate_property(maplist, meta_predicate(I)).
%@ false.
?- predicate_property(maplist( = ), meta_predicate(I)).
%@ false.

Is it for N=0,1 a bug or normal ? As maplist/N seems not a meta predicate
for N = 0,1, I had to add a local rule the maplist/N is a meta predicate
for N = 0, 1, because of a reason below.

Of course, for N >= 2, maplist/N are meta predicates:

?- predicate_property(maplist(=, []), meta_predicate(I)).
%@ I = maplist(1, ?).
?- predicate_property(maplist(=, [], []), meta_predicate(I)).
%@ I = maplist(2, ?, ?).
?- predicate_property(maplist(=, [], [], []), meta_predicate(I)).
%@ I = maplist(3, ?, ?, ?).

BTW, I have a term_expansion (pack/pac) for handling
emacs buffer region. An example among many others is this:

handle([trim, sort, lines]) --> region,
split,
remove([]),
maplist(phrase(wl("[\s\t]*"))),
sort,
maplist(pred([L, [L,"\n"]])),
overwrite.

in which maplist/1 appears in the DCG clause body.

If query
predicate_property(maplist(phrase(wl("[\s\t]*"))), meta_predicate(I))
would return I = maplist(0), then the term_expansion expands the above DCG rule
like this:

handle([trim,sort,lines],A1,A2):-(true,A3=A1),region(A3,A4),split(A4,A5),
remove([],A5,A6),maplist(‘pac#8’,A6,A7),sort(A7,A8),
maplist(‘pac#9’,A8,A9),overwrite(A9,A2) .

‘nt#1’([9|A],B):-‘nt#1’(A,B) .
‘nt#1’([32|A],B):-‘nt#1’(A,B) .
‘nt#1’(A,A) .
‘pac#8’(A,B):-‘nt#1’(A,B) .
‘pac#9’(A,[A,"\n"]) .

In fact, this codes is an output of the term expansion
after adding an ad hoc rule to the term_expansion
to tell that maplist/1 is a meta_predicate.

Kuniaki Mukai

Note that there are no maplist/0 or maplist/1 predicates. The minimum arity for the maplist family of predicate is 2 as you need always an argument for the closure and one or more list arguments.

Thanks.

I see. That is, for the closure maplist(phrase(…)) in the body of DCG rule,

maplist(phrase(…), _, _) in stead should be checked for meta_predicate with predicate_property.

Kuniaki Mukai

Based on Pmoura’s remark on non existing maplist/1,

I have managed to find a simple workaround (W) below for expanding meta arguments

which appear in goals as meta arguments including DCG rules.

(W) To tell that the argument of maplist/1 is a meta argument.

:- meta_predicate user:maplist(0).

user:maplist(_).

As far as I observe and in fact, workaround (W) works exactly as I expected.

For example, the regex and closure in (A) are successfully

expanded as in © and (D) via (B).

(A) Source of handle in DCG rule.

handle([trim, sort, lines]) --> region,

		  split,

		  remove([]),

		  maplist(phrase(wl("[\s\t]*"))),

		  sort,

		  maplist(pred([L, [L,"\n"]])),

		  overwrite.

(B) Expanded intermediate codes for (A).

handle([trim,sort,lines],A1,A2):-(true,A3=A1),region(A3,A4),

split(A4,A5),remove([],A5,A6),[]:maplist('pac#3',A6,A7),

sort(A7,A8),[]:maplist('pac#4',A8,A9),overwrite(A9,A2) .

© Generated helper predicates for (A).

‘nt#2’([9|A],B):-‘nt#2’(A,B) .

‘nt#2’([32|A],B):-‘nt#2’(A,B) .

‘nt#2’(A,A) .

‘pac#3’(A,B):-‘nt#2’(A,B) .

‘pac#4’(A,[A,"\n"]) .

(D) Final expanded clauses for (A) via builtin maplist.

handle([trim, sort, lines], A, I) :-

true,

B=A,

region(B, C),

split(C, D),

remove([], D, E),

‘__aux_maplist/3_ejockey:pac#23+0’(E, F),

sort(F, G),

‘__aux_maplist/3_ejockey:pac#24+0’(G, H),

overwrite(H, I).

Kuniaki Mukai