Jump to content

First-class functions: Difference between revisions

Added XBS language
(omit from Scratch)
(Added XBS language)
Line 3,106:
0.5
0.5
</pre>
 
=={{header|XBS}}==
<lang xbs>func cube(x:number):number{
send x^3;
}
func cuberoot(x:number):number{
send x^(1/3);
}
 
func compose(f:function,g:function):function{
send func(n:number){
send f(g(n));
}
}
 
const a:[function]=[math.sin,math.cos,cube];
const b:[function]=[math.asin,math.acos,cuberoot];
 
each a as k,v{
log(compose(v,b[k])(0.5))
}</lang>
{{out}}
<pre>
0.5
0.4999999999999999
0.5000000000000001
</pre>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.