Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View 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))

View 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

View 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

View 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

View file

@ -0,0 +1,4 @@
(defun curry (f arg)
(lambda (x)
(apply f
(list arg x))))

View file

@ -0,0 +1 @@
(funcall (curry #'+/2 10) 10)

View file

@ -0,0 +1,4 @@
proc addN[T](n: T): auto = (proc(x: T): T = x + n)
let add2 = addN(2)
echo add2(7)

View file

@ -0,0 +1,6 @@
import future
proc addM[T](n: T): auto = (x: T) => x + n
let add3 = addM(3)
echo add3(7)

View file

@ -0,0 +1,3 @@
2 #+ curry => 2+
5 2+ .
7 ok

View file

@ -0,0 +1,2 @@
var adder = 1.method(:add);
say adder(3); #=> 4

View 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

View 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

View 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

View 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

View 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
]]
}

View file

@ -0,0 +1,3 @@
def plus(x): . + x;
def plus5: plus(5);

View file

@ -0,0 +1 @@
3 | plus5