Content deleted Content added
→Uses: Added closures |
→Uses: Added currying |
||
Line 67:
It would clearly be very impractical to create a function for every possible comparison function and may be too inconvenient to keep the threshold around for further use. Regardless of the reason why a closure is used the anonymous function is what the contains the functionality that does the comparing.
===Currying===
{{main|currying}}
Currying is transforming a function from multiple inputs to fewer inputs.
<source lang="python">
def divide(x,y):
return x/y
def divisor(d):
return lambda x: divide(x,d)
half = divisor(2)
third = divisor(3)
print half(32), third(32)
16 10
print half(40), third(40)
20 13
</source>
While the use of anonymous functions is perhaps not common with currying it still can be used. In the above example, the function divisor generates functions with a specified divisor. The functions half and third curry the divide function with a fixed divisor.
==List of languages==
|