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,2 @@
fns: {n: x; {n expt 2}} map range[10]
(8 elem fns)[]

View file

@ -0,0 +1,9 @@
shared void run() {
//create a list of closures with a list comprehension
value closures = [for(i in 0:10) () => i ^ 2];
for(i->closure in closures.indexed) {
print("closure number ``i`` returns: ``closure()``");
}
}

View file

@ -0,0 +1,4 @@
(define (fgen i) (lambda () (* i i)))
(define fs (for/vector ((i 10)) (fgen i))) ;; vector of 10 anonymous functions
((vector-ref fs 5)) ;; calls fs[5]
→ 25

View file

@ -0,0 +1,33 @@
' FB 1.05.0 Win64
Type Closure
Private:
index As Integer
Public:
Declare Constructor(index As Integer = 0)
Declare Function Square As Integer
End Type
Constructor Closure(index As Integer = 0)
This.index = index
End Constructor
Function Closure.Square As Integer
Return index * index
End Function
Dim a(1 To 10) As Closure
' create Closure objects which capture their index
For i As Integer = 1 To 10
a(i) = Closure(i)
Next
' call the Square method on all but the last object
For i As Integer = 1 to 9
Print a(i).Square
Next
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,2 @@
> (set funcs (list-comp ((<- m (lists:seq 1 10)))
(lambda () (math:pow m 2))))

View file

@ -0,0 +1,5 @@
(#Fun<lfe_eval.23.101079464> #Fun<lfe_eval.23.101079464>
#Fun<lfe_eval.23.101079464> #Fun<lfe_eval.23.101079464>
#Fun<lfe_eval.23.101079464> #Fun<lfe_eval.23.101079464>
#Fun<lfe_eval.23.101079464> #Fun<lfe_eval.23.101079464>
#Fun<lfe_eval.23.101079464> #Fun<lfe_eval.23.101079464>)

View file

@ -0,0 +1,8 @@
> (funcall (car funcs))
1.0
> (funcall (cadr funcs))
4.0
> (funcall (cadddr funcs))
16.0
> (funcall (lists:nth 8 funcs))
64.0

View file

@ -0,0 +1,24 @@
-- parent script "CallFunction"
property _code
-- if the function is supposed to return something, the code must contain a line that starts with "res="
on new (me, code)
me._code = code
return me
end
on call (me)
----------------------------------------
-- If custom arguments were passed, evaluate them in the current context.
-- Note: in the code passed to the constructor they have to be referenced
-- as arg[1], arg[2], ...
arg = []
repeat with i = 3 to the paramCount
arg[i-2] = param(i)
end repeat
----------------------------------------
res = VOID
do(me._code)
return res
end

View file

@ -0,0 +1,8 @@
funcs = []
repeat with i = 1 to 10
code = "res="&i&"*"&i
funcs[i] = script("CallFunction").new(code)
end repeat
put call(funcs[3], _movie)
-- 9

View file

@ -0,0 +1,15 @@
funcs = []
repeat with i = 1 to 10
code = ""
put "res = "&i&"*"&i &RETURN after code
put "repeat with i = 1 to arg.count" &RETURN after code
put " res = res + arg[i]" &RETURN after code
put "end repeat" after code
funcs[i] = script("CallFunction").new(code)
end repeat
put call(funcs[3], _movie, 23)
-- 32
put call(funcs[7], _movie, 4, 5, 6)
-- 64

View file

@ -0,0 +1,9 @@
var funcs: seq[proc(): int] = @[]
for i in 0..9:
(proc =
let x = i
funcs.add(proc (): int = x * x))()
for i in 0..8:
echo "func[", i, "]: ", funcs[i]()

View file

@ -0,0 +1,2 @@
: newClosure(i) #[ i sq ] ;
10 seq map(#newClosure) at(7) perform .

View file

@ -0,0 +1,9 @@
x = funcs(7)
see x + nl
func funcs n
fn = list(n)
for i = 1 to n
fn[i] =i*i
next
return fn

View file

@ -0,0 +1,7 @@
var f = (
0 ..^ 9 -> map {|i| func(j){i * j} }
);
0 ..^ 8 -> each { |j|
say f[j](j);
}

View file

@ -0,0 +1,7 @@
var f = 10.of { |i|
func(j){i * j}
}
9.times { |j|
say f[j-1](j);
}

View file

@ -0,0 +1,9 @@
var fnlist = {};
for var i = 0; i < 10; i++ {
fnlist[i] = function() {
return i * i;
};
}
print(fnlist[3]()); // prints 9
print(fnlist[5]()); // prints 25

View file

@ -0,0 +1,8 @@
var fnlist = map(range(10), function(k, v) {
return function() {
return v * v;
};
});
print(fnlist[3]()); // prints 9
print(fnlist[5]()); // prints 25

View file

@ -0,0 +1,5 @@
var funcs: [() -> Int] = []
for var i = 0; i < 10; i++ {
funcs.append({ i * i })
}
println(funcs[3]()) // prints 100

View file

@ -0,0 +1,5 @@
var funcs: [() -> Int] = []
for i in 0..<10 {
funcs.append({ i * i })
}
println(funcs[3]()) // prints 9

View file

@ -0,0 +1,5 @@
var funcs: [() -> Int] = []
for var i = 0; i < 10; i++ {
funcs.append({ [i] in i * i })
}
println(funcs[3]()) // prints 9

View file

@ -0,0 +1,2 @@
let funcs = [] + map(0..<10) {i in { i * i }}
println(funcs[3]()) // prints 9