Function composition: Difference between revisions

Add an example for Janet
(Add lang example)
(Add an example for Janet)
Line 1,510:
 
Note: <code>1&o.</code> is sine (mnemonic: sine is an odd circular function), <code>2&o.</code> is cosine (cosine is an even circular function), <code>%:</code> is square root, <code>>.</code> is ceiling, <code>|</code> is absolute value and <code>1&+</code> adds 1.
 
=={{header|Janet}}==
 
Janet supports function composition with the [https://janet-lang.org/api/misc.html#comp <code>comp</code>] function.
 
<syntaxhighlight lang="janet">(defn fahrenheit->celsius [deg-f]
(/ (* (- deg-f 32) 5) 9))
 
(defn celsius->kelvin [deg-c]
(+ deg-c 273.15))
 
(def fahrenheit->kelvin (comp celsius->kelvin fahrenheit->celsius))
 
(fahrenheit->kelvin 72) // 295.372
</syntaxhighlight>
 
=={{header|Java}}==