2:- module(coordination,[coordMacro/2,argCard/2]). 3:- use_module(boxer(slashes)). 4 5/* ========================================================================= 6 Coordination Macros 7========================================================================= */ 8 9coordMacro(N,lam(C,lam(X2,lam(X1,Body)))):- 10 addLambdas(N,[],C,X2,X1,Body). 11 12 13/* ========================================================================= 14 Adding right amount of lambdas 15========================================================================= */ 16 17addLambdas(0,Vars,C,X,Y,lam(A,app(app(C,X1),Y1))):- !, 18 addApplications([A|Vars],X,Y,X1,Y1). 19 20addLambdas(N,Vars,C,X,Y,lam(A,Body)):- 21 M is N - 1, addLambdas(M,[A|Vars],C,X,Y,Body). 22 23 24/* ========================================================================= 25 Adding right amount of applications 26========================================================================= */ 27 28addApplications([A],X,Y,app(X,A),app(Y,A)):- !. 29 30addApplications([A|L],X,Y,app(X1,A),app(Y1,A)):- 31 addApplications(L,X,Y,X1,Y1). 32 33 34/* ========================================================================= 35 Argument Cardinality 36========================================================================= */ 37 38argCard(_:_,C):- !, C = 0. 39argCard(X/_,C):- !, argCard(X,N), C is N + 1. 40argCard(X\_,C):- !, argCard(X,N), C is N + 1. 41argCard(_,0)