Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/First-class-functions/E/first-class-functions-1.e
Normal file
9
Task/First-class-functions/E/first-class-functions-1.e
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
def sin(x) { return x.sin() }
|
||||
def cos(x) { return x.cos() }
|
||||
def asin(x) { return x.asin() }
|
||||
def acos(x) { return x.acos() }
|
||||
def cube(x) { return x ** 3 }
|
||||
def curt(x) { return x ** (1/3) }
|
||||
|
||||
def forward := [sin, cos, cube]
|
||||
def reverse := [asin, acos, curt]
|
||||
3
Task/First-class-functions/E/first-class-functions-2.e
Normal file
3
Task/First-class-functions/E/first-class-functions-2.e
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def compose(f, g) {
|
||||
return fn x { f(g(x)) }
|
||||
}
|
||||
9
Task/First-class-functions/E/first-class-functions-3.e
Normal file
9
Task/First-class-functions/E/first-class-functions-3.e
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
? def x := 0.5 \
|
||||
> for i => f in forward {
|
||||
> def g := reverse[i]
|
||||
> println(`x = $x, f = $f, g = $g, compose($f, $g)($x) = ${compose(f, g)(x)}`)
|
||||
> }
|
||||
|
||||
x = 0.5, f = <sin>, g = <asin>, compose(<sin>, <asin>)(0.5) = 0.5
|
||||
x = 0.5, f = <cos>, g = <acos>, compose(<cos>, <acos>)(0.5) = 0.4999999999999999
|
||||
x = 0.5, f = <cube>, g = <curt>, compose(<cube>, <curt>)(0.5) = 0.5000000000000001
|
||||
Loading…
Add table
Add a link
Reference in a new issue