A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
24
Task/First-class-functions/Prolog/first-class-functions.pro
Normal file
24
Task/First-class-functions/Prolog/first-class-functions.pro
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
:- use_module(library(lambda)).
|
||||
|
||||
|
||||
compose(F,G, FG) :-
|
||||
FG = \X^Z^(call(G,X,Y), call(F,Y,Z)).
|
||||
|
||||
cube(X, Y) :-
|
||||
Y is X ** 3.
|
||||
|
||||
cube_root(X, Y) :-
|
||||
Y is X ** (1/3).
|
||||
|
||||
first_class :-
|
||||
L = [sin, cos, cube],
|
||||
IL = [asin, acos, cube_root],
|
||||
|
||||
% we create the composed functions
|
||||
maplist(compose, L, IL, Lst),
|
||||
|
||||
% we call the functions
|
||||
maplist(call, Lst, [0.5,0.5,0.5], R),
|
||||
|
||||
% we display the results
|
||||
maplist(writeln, R).
|
||||
Loading…
Add table
Add a link
Reference in a new issue