First-class functions/Use numbers analogously: Difference between revisions

added Ursala
m (→‎{{header|Ruby}}: some verbage)
(added Ursala)
Line 128:
4 * 0.25 * 0.5 = 0.5
6 * 0.166667 * 0.5 = 0.5</pre>
 
=={{header|Ursala}}==
The form is very similar to the first class functions task solution
in Ursala, except that the multiplier function takes the place of the
composition operator (+), and is named in compliance
with the task specification.
<lang Ursala>
#import std
#import flo
 
numbers = <2.,4.,plus(2.,4.)>
inverses = <0.5,0.25,div(1.,plus(2.,4.))>
 
multiplier = //times+ times
 
#cast %eL
 
main = (gang multiplier*p\<x,y,z> <xi,yi,zi>) 0.5
</lang>
The multiplier could have been written in pattern
matching form like this.
<lang Ursala>
multiplier("a","b") "c" = times(times("a","b"),"c")
</lang>
The main program might also have been written with an
anonymous function like this.
<lang Ursala>
main = (gang (//times+ times)*p\<x,y,z> <xi,yi,zi>) 0.5
</lang>
output:
<pre>
<5.000000e-01,5.000000e-01,5.000000e-01>
</pre>
 
 
{{omit from|Java|Can't pass around expressions like that.}}
Anonymous user