#fp-prolog
Language:
plainWritten by
AtnNn on 2007-11-27 01:12:43
% Usage:
%
% | ?- map(fun(A,B,B is A+1),[1,2,3],L).
%
% L = [2,3,4] ?
map(F,[],[]).
map(F,[X|XS],[Y|YS]) :- apply(F,[X,Y]), map(F,XS,YS).
foldl(F,I,[],I).
foldl(F,I,[X|XS],Y) :- apply(F,[I,X,Z]), foldl(F,Z,XS,Y).
foldr(F,I,[],I).
foldr(F,I,[X|XS],Y) :- foldr(F,I,XS,Z), apply(F,[X,Z,Y]).
apply(F,A) :- F =.. L, append(L,A,K), G =.. K, G.
fun(V,F,A) :-
copy_term([V|F],[NV|NF]),
S=(NV=A), S, NF.
lambda(A,B,F) :- copy_term(fun(A,B),F).
fun(V1,V2,F,A1,A2) :-
copy_term([V1,V2,F],[NV1,NV2,NF]),
S=([NV1|NV2]=[A1|A2]), S, NF.
lambda(A1,A2,B,F) :- copy_term(fun(A1,A2,B),F).