Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
24
Task/Higher-order-functions/CLU/higher-order-functions.clu
Normal file
24
Task/Higher-order-functions/CLU/higher-order-functions.clu
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
% Functions can be passed to other functions using the 'proctype'
|
||||
% type generator. The same works for iterators, using 'itertype'
|
||||
|
||||
% Here are two functions
|
||||
square = proc (n: int) returns (int) return (n*n) end square
|
||||
cube = proc (n: int) returns (int) return (n*n*n) end cube
|
||||
|
||||
% Here is a function that takes another function
|
||||
do_calcs = proc (from, to: int, title: string,
|
||||
fn: proctype (int) returns (int))
|
||||
po: stream := stream$primary_output()
|
||||
|
||||
stream$putleft(po, title, 8)
|
||||
stream$puts(po, " -> ")
|
||||
for i: int in int$from_to(from,to) do
|
||||
stream$putright(po, int$unparse(fn(i)), 5)
|
||||
end
|
||||
stream$putc(po, '\n')
|
||||
end do_calcs
|
||||
|
||||
start_up = proc ()
|
||||
do_calcs(1, 10, "Squares", square)
|
||||
do_calcs(1, 10, "Cubes", cube)
|
||||
end start_up
|
||||
Loading…
Add table
Add a link
Reference in a new issue