June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,6 +1,10 @@
|
|||
{{Wikipedia|Currying}}
|
||||
Create a simple demonstrative example of [[wp:Currying|Currying]] in the specific language.
|
||||
|
||||
|
||||
;Task:
|
||||
Create a simple demonstrative example of [[wp:Currying|Currying]] in a specific language.
|
||||
|
||||
Add any historic details as to how the feature made its way into the language.
|
||||
<!-- from: http://en.wikipedia.org/w/index.php?title=Currying&direction=prev&oldid=142127294 -->
|
||||
[[Category:Functions and subroutines]]
|
||||
<br><br>
|
||||
|
|
|
|||
32
Task/Currying/C/currying.c
Normal file
32
Task/Currying/C/currying.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*Abhishek Ghosh, 24th October 2017*/
|
||||
#include<stdarg.h>
|
||||
#include<stdio.h>
|
||||
|
||||
long int factorial(int n){
|
||||
if(n>1)
|
||||
return n*factorial(n-1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
long int sumOfFactorials(int num,...){
|
||||
va_list vaList;
|
||||
long int sum = 0;
|
||||
|
||||
va_start(vaList,num);
|
||||
|
||||
while(num--)
|
||||
sum += factorial(va_arg(vaList,int));
|
||||
|
||||
va_end(vaList);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("\nSum of factorials of [1,5] : %ld",sumOfFactorials(5,1,2,3,4,5));
|
||||
printf("\nSum of factorials of [3,5] : %ld",sumOfFactorials(3,3,4,5));
|
||||
printf("\nSum of factorials of [1,3] : %ld",sumOfFactorials(3,1,2,3));
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
Task/Currying/Ceylon/currying.ceylon
Normal file
10
Task/Currying/Ceylon/currying.ceylon
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
shared void run() {
|
||||
|
||||
function divide(Integer x, Integer y) => x / y;
|
||||
|
||||
value partsOf120 = curry(divide)(120);
|
||||
|
||||
print("half of 120 is ``partsOf120(2)``
|
||||
a third is ``partsOf120(3)``
|
||||
and a quarter is ``partsOf120(4)``");
|
||||
}
|
||||
8
Task/Currying/Factor/currying-1.factor
Normal file
8
Task/Currying/Factor/currying-1.factor
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
IN: scratchpad 2 [ 3 + ] curry
|
||||
|
||||
--- Data stack:
|
||||
[ 2 3 + ]
|
||||
IN: scratchpad call
|
||||
|
||||
--- Data stack:
|
||||
5
|
||||
9
Task/Currying/Factor/currying-2.factor
Normal file
9
Task/Currying/Factor/currying-2.factor
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
IN: scratchpad [ 3 4 ] [ 5 + ] compose
|
||||
|
||||
--- Data stack:
|
||||
[ 3 4 5 + ]
|
||||
IN: scratchpad call
|
||||
|
||||
--- Data stack:
|
||||
3
|
||||
9
|
||||
4
Task/Currying/Factor/currying-3.factor
Normal file
4
Task/Currying/Factor/currying-3.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
IN: scratchpad { 1 2 3 4 5 } [ 1 + ] { 2 / } append map
|
||||
|
||||
--- Data stack:
|
||||
{ 1 1+1/2 2 2+1/2 3 }
|
||||
5
Task/Currying/Factor/currying-4.factor
Normal file
5
Task/Currying/Factor/currying-4.factor
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
USE: fry
|
||||
IN: scratchpad 2 3 '[ _ _ + ]
|
||||
|
||||
--- Data stack:
|
||||
[ 2 3 + ]
|
||||
4
Task/Currying/Factor/currying-5.factor
Normal file
4
Task/Currying/Factor/currying-5.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
IN: scratchpad { 1 2 3 4 5 } [ 1 + ] '[ 2 + @ ] map
|
||||
|
||||
--- Data stack:
|
||||
{ 4 5 6 7 8 }
|
||||
10
Task/Currying/Python/currying-3.py
Normal file
10
Task/Currying/Python/currying-3.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
>>> from functools import partial
|
||||
>>> from operator import add
|
||||
>>> add2 = partial(add, 2)
|
||||
>>> add2
|
||||
functools.partial(<built-in function add>, 2)
|
||||
>>> add2(7)
|
||||
9
|
||||
>>> double = partial(map, lambda x: x*2)
|
||||
>>> print(*double(range(5)))
|
||||
0 2 4 6 8
|
||||
13
Task/Currying/Python/currying-4.py
Normal file
13
Task/Currying/Python/currying-4.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
>>> from toolz import curry
|
||||
>>> import operator
|
||||
>>> add = curry(operator.add)
|
||||
>>> add2 = add(2)
|
||||
>>> add2
|
||||
<built-in function add>
|
||||
>>> add2(7)
|
||||
9
|
||||
>>> # Toolz also has pre-curried versions of most HOFs from builtins, stdlib, and toolz
|
||||
>>>from toolz.curried import map
|
||||
>>> double = map(lambda x: x*2)
|
||||
>>> print(*double(range(5)))
|
||||
0 2 4 6 8
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(conservative_impl_trait)]
|
||||
fn add_n(n : i32) -> impl Fn(i32) -> i32 {
|
||||
move |x| n + x
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue