このディレクトリの索引

#  高階述語の書き方
#  
#  項複写の用例
#  

高階述語の利用([],_,[]).
高階述語の利用([A|R1],P,[_引数2|R4]) :-
        高階述語の項複写(P,_引数1,_引数2,P2),
        A = _引数1,
        call(P),
        高階述語の利用(R1,P2,R4).

高階述語の項複写(P,_引数1,_引数2,P2) :-
        copy_term(P,P2),
        P =..[_,_引数1,_引数2].

pow(X,Y) :- Y is X * X.

add1(X,Y) :- Y is X + 1.


#  swipl -f temp2.pro % library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 2,224 bytes
%  % ./temp2.pro compiled 0.00 sec, 1,544 bytes
%  Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 5.10.4)
%  Copyright (c) 1990-2011 University of Amsterdam, VU Amsterdam
%  SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
%  and you are welcome to redistribute it under certain conditions.
%  Please visit http://www.swi-prolog.org for details.
%  
%  For help, use ?- help(Topic). or ?- apropos(Word).

?- 高階述語の利用([1,2,3],add1(A,B),X).
A = 1,
B = 2,
X = [2, 3, 4].

?- 高階述語の利用([1,2,3],pow(A,B),X).
A = B, B = 1,
X = [1, 4, 9].

?-