Currying: Difference between revisions

No edit summary
Line 1,024:
Called with a number of values lesser than the number of arguments a function memorizes the given values and returns a function waiting for the missing ones.
<lang scheme>
1) just define function asa usualbinary function:
'{def power {lambda {:a :b} {pow :a :b}}}
-> power
-> {def power {lambda {:a :b} {pow :a :b}}}
2) and use it:
'{power 2 8}
-> 256
 
'{S.map {power 2} {S.serie 1 10}}
'{{power 2} 8} // {power 2} is a function waiting for a number
-> 2 4 8 16 32 64 128 256 512 1024
-> 256
 
'{S.map {power 2} {S.serie 1 10}} // S.map applies the {power 2} unary
-> 2 4 8 16 32 64 128 256 512 1024 // function to a sequence of numbers
</lang>