Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 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