44 lines
1022 B
Plaintext
44 lines
1022 B
Plaintext
use std, math
|
|
|
|
let my_asin = new Function (.:<any,real x>:. -> real {asin x})
|
|
let my__sin = new Function (.:<any,real x>:. -> real { sin x})
|
|
let sinasin = my__sin o my_asin
|
|
print sin asin 0.5
|
|
print *my__sin 0.0
|
|
print *sinasin 0.5
|
|
~my_asin
|
|
~my__sin
|
|
~sinasin
|
|
|
|
=: <Function f> o <Function g> := -> Function {compose f g}
|
|
|
|
.:compose <Function f, Function g>:. -> Function
|
|
use array
|
|
let d = (new array of 2 Function)
|
|
(d[0]) = f ; (d[1]) = g
|
|
let c = new Function (.:<array of Function fg, real x>:. -> real {
|
|
*fg[0]( *fg[1](x) )
|
|
}) (d)
|
|
c.del = .:<any>:.{free any}
|
|
c
|
|
|
|
class Function
|
|
function(any)(real)->(real) func
|
|
any data
|
|
function(any) del
|
|
|
|
=: * <Function f> <real x> := -> real
|
|
Cgen "(*("(f.func)"))("(f.data)", "(x)")"
|
|
|
|
.: del Function <Function f> :.
|
|
unless f.del is nil
|
|
call f.del with f.data
|
|
free f
|
|
=: ~ <Function f> := {del Function f}
|
|
|
|
.: new Function <function(any)(real)-\>real func> (<any data>):. -> Function
|
|
let f = new Function
|
|
f.func = func
|
|
f.data = data
|
|
f
|