Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
19
Task/Currying/EchoLisp/currying.echolisp
Normal file
19
Task/Currying/EchoLisp/currying.echolisp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
;;
|
||||
;; curry functional definition
|
||||
;; (define (curry proc . left-args) (lambda right-args (apply proc (append left-args right-args))))
|
||||
;;
|
||||
;; right-curry
|
||||
;; (define (rcurry proc . right-args) (lambda left-args (apply proc (append left-args right-args))))
|
||||
;;
|
||||
|
||||
(define add42 (curry + 42))
|
||||
(add42 666) → 708
|
||||
|
||||
(map (curry cons 'simon) '( gallubert garfunkel et-merveilles))
|
||||
→ ((simon . gallubert) (simon . garfunkel) (simon . et-merveilles))
|
||||
(map (rcurry cons 'simon) '( gallubert garfunkel et-merveilles))
|
||||
→ ((gallubert . simon) (garfunkel . simon) (et-merveilles . simon))
|
||||
|
||||
;Implementation : result of currying :
|
||||
(curry * 2 3 (+ 2 2))
|
||||
→ (λ _#:g1004 (#apply-curry #* (2 3 4) _#:g1004))
|
||||
14
Task/Currying/Eero/currying-1.eero
Normal file
14
Task/Currying/Eero/currying-1.eero
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#import <stdio.h>
|
||||
|
||||
int main()
|
||||
|
||||
addN := (int n)
|
||||
int adder(int x)
|
||||
return x + n
|
||||
return adder
|
||||
|
||||
add2 := addN(2)
|
||||
|
||||
printf( "Result = %d\n", add2(7) )
|
||||
|
||||
return 0
|
||||
12
Task/Currying/Eero/currying-2.eero
Normal file
12
Task/Currying/Eero/currying-2.eero
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#import <stdio.h>
|
||||
|
||||
int main()
|
||||
|
||||
addN := (int n)
|
||||
return (int x | return x + n)
|
||||
|
||||
add2 := addN(2)
|
||||
|
||||
printf( "Result = %d\n", add2(7) )
|
||||
|
||||
return 0
|
||||
18
Task/Currying/FreeBASIC/currying.freebasic
Normal file
18
Task/Currying/FreeBASIC/currying.freebasic
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Type CurriedAdd
|
||||
As Integer i
|
||||
Declare Function add(As Integer) As Integer
|
||||
End Type
|
||||
|
||||
Function CurriedAdd.add(j As Integer) As Integer
|
||||
Return i + j
|
||||
End Function
|
||||
|
||||
Function add (i As Integer) as CurriedAdd
|
||||
Return Type<CurriedAdd>(i)
|
||||
End Function
|
||||
|
||||
Print "3 + 4 ="; add(3).add(4)
|
||||
Print "2 + 6 ="; add(2).add(6)
|
||||
Sleep
|
||||
4
Task/Currying/LFE/currying-1.lfe
Normal file
4
Task/Currying/LFE/currying-1.lfe
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(defun curry (f arg)
|
||||
(lambda (x)
|
||||
(apply f
|
||||
(list arg x))))
|
||||
1
Task/Currying/LFE/currying-2.lfe
Normal file
1
Task/Currying/LFE/currying-2.lfe
Normal file
|
|
@ -0,0 +1 @@
|
|||
(funcall (curry #'+/2 10) 10)
|
||||
4
Task/Currying/Nim/currying-1.nim
Normal file
4
Task/Currying/Nim/currying-1.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
proc addN[T](n: T): auto = (proc(x: T): T = x + n)
|
||||
|
||||
let add2 = addN(2)
|
||||
echo add2(7)
|
||||
6
Task/Currying/Nim/currying-2.nim
Normal file
6
Task/Currying/Nim/currying-2.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import future
|
||||
|
||||
proc addM[T](n: T): auto = (x: T) => x + n
|
||||
|
||||
let add3 = addM(3)
|
||||
echo add3(7)
|
||||
3
Task/Currying/Oforth/currying.oforth
Normal file
3
Task/Currying/Oforth/currying.oforth
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
2 #+ curry => 2+
|
||||
5 2+ .
|
||||
7 ok
|
||||
2
Task/Currying/Sidef/currying-1.sidef
Normal file
2
Task/Currying/Sidef/currying-1.sidef
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var adder = 1.method(:add);
|
||||
say adder(3); #=> 4
|
||||
12
Task/Currying/Sidef/currying-2.sidef
Normal file
12
Task/Currying/Sidef/currying-2.sidef
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
func curry(f, *args1) {
|
||||
func (*args2) {
|
||||
f(args1..., args2...);
|
||||
}
|
||||
}
|
||||
|
||||
func add(a, b) {
|
||||
a + b
|
||||
}
|
||||
|
||||
var adder = curry(add, 1);
|
||||
say adder(3); #=>4
|
||||
5
Task/Currying/Swift/currying-1.swift
Normal file
5
Task/Currying/Swift/currying-1.swift
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
func addN(n:Int)->Int->Int { return {$0 + n} }
|
||||
|
||||
var add2 = addN(2)
|
||||
println(add2) // (Function)
|
||||
println(add2(7)) // 9
|
||||
5
Task/Currying/Swift/currying-2.swift
Normal file
5
Task/Currying/Swift/currying-2.swift
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
func addN(n:Int)(x:Int) -> Int { return x + n }
|
||||
|
||||
var add2 = addN(2)
|
||||
println(add2) // (Function)
|
||||
println(add2(x:7)) // 9
|
||||
5
Task/Currying/Swift/currying-3.swift
Normal file
5
Task/Currying/Swift/currying-3.swift
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
func addN(n:Int)(_ x:Int) -> Int { return x + n }
|
||||
|
||||
var add2 = addN(2)
|
||||
println(add2) // (Function)
|
||||
println(add2(7)) // 9
|
||||
20
Task/Currying/Wortel/currying.wortel
Normal file
20
Task/Currying/Wortel/currying.wortel
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
@let {
|
||||
addOne \+ 1
|
||||
subtractFrom1 \- 1
|
||||
subtract1 \~- 1
|
||||
|
||||
subtract1_2 &\- [. 1]
|
||||
|
||||
add ^+
|
||||
; partial apply to named functions
|
||||
addOne_2 \add 1
|
||||
|
||||
; testing
|
||||
[[
|
||||
!addOne 5 ; returns 6
|
||||
!subtractFrom1 5 ; returns -4
|
||||
!subtract1 5 ; returns 4
|
||||
!subtract1_2 5 ; returns 4
|
||||
!addOne_2 5 ; returns 6
|
||||
]]
|
||||
}
|
||||
3
Task/Currying/jq/currying-1.jq
Normal file
3
Task/Currying/jq/currying-1.jq
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def plus(x): . + x;
|
||||
|
||||
def plus5: plus(5);
|
||||
1
Task/Currying/jq/currying-2.jq
Normal file
1
Task/Currying/jq/currying-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
3 | plus5
|
||||
Loading…
Add table
Add a link
Reference in a new issue