:- module(_,_).

% Meta-calls (call/1) and implementing apply
% ------------------------------------------

% call/1 example: simple call

p(X) :- call(X). 

q(a,1).
q(b,2).

% Try (ask also for more solutions):
% ?- G = q(a,Y), p(G).
% ?- G = member(Y,[1,2,3]), p(G).


% call/1 example: constructing apply

apply(P,Args) :-
    G =.. [P|Args],
    call(G).

% Try: 
% ?- P = q, apply(P,[a,Y]).
% ?- P = q, apply(P,[X,Y]).

maptuples(_P,[]).
maptuples(P,[Tuple|RTuples]) :-
    apply(P,Tuple),
    maptuples(P,RTuples).

% Try: 
%  ?- maptuples(q,[[a,X],[b,Y]]).
/* ?- maptuples(append, [ [ [a],[c,d], X ],
                          [ X,  [e,f], Y ],
                          [ X,  Y,     Z ]  ]).
*/
