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,17 @@
shared void run() {
Integer|Float accumulator
(variable Integer|Float n)
(Integer|Float i)
=> switch (i)
case (is Integer)
(n = n.plusInteger(i))
case (is Float)
(n = i + (switch(prev = n)
case (is Float) prev
case (is Integer) prev.float));
value x = accumulator(1);
print(x(5));
print(accumulator(3));
print(x(2.3));
}

View file

@ -0,0 +1,17 @@
PROGRAM ACCUMULATOR
PROCEDURE ACCUMULATOR(SUM,N,A->SUM)
IF NOT A THEN SUM=N ELSE SUM=SUM+N
END PROCEDURE
BEGIN
PRINT(CHR$(12);) ! CLS
ACCUMULATOR(X,1,FALSE->X) ! INIT FIRST ACCUMULATOR
ACCUMULATOR(X,-15,TRUE->X)
ACCUMULATOR(X,2.3,TRUE->X)
ACCUMULATOR(Z,3,FALSE->Z) ! INIT SECOND ACCUMULATOR
ACCUMULATOR(Z,5,TRUE->Z)
ACCUMULATOR(Z,2.3,TRUE->Z)
PRINT(X,Z)
END PROGRAM

View file

@ -0,0 +1,10 @@
(define-syntax-rule (inc x v) (set! x (+ x v)))
(define (accumulator (sum 0)) (lambda(x) (inc sum x) sum))
(define x (accumulator 1)) → x
(x 5) → 6
;; another closure
(accumulator 3) → (🔒 λ (_x) (📝 #set! sum (#+ sum _x)) sum)
(x 2.3) → 8.3

View file

@ -0,0 +1,49 @@
' FB 1.05.0 Win64
' uses overloaded methods to deal with the integer/float aspect (long and single are both 4 bytes)
Type Bar
Public:
Declare Constructor(As Long)
Declare Constructor(As Single)
Declare Function g(As Long) As Long
Declare Function g(As Single) As Single
Private:
As Single sum_ '' can't be altered by external code
End Type
Constructor Bar(i As Long)
sum_ = i
End Constructor
Constructor Bar(s As Single)
sum_ = s
End Constructor
Function Bar.g(i As Long) As Long
sum_ += i
Return sum_ '' would round down to a Long if non-integral Singles had been added previously
End Function
Function Bar.g(s As Single) As Single
sum_ += s
Return sum_
End Function
Function foo Overload(i As Long) As Bar '' returns a Bar object rather than a pointer to Bar.g
Dim b As Bar = Bar(i)
Return b
End Function
Function foo Overload(s As Single) As Bar '' overload of foo to deal with Single argument
Dim b As Bar = Bar(s)
Return b
End Function
Dim x As Bar = foo(1) '' assigns Bar object to x
x.g(5) '' calls the Long overload of g on the Bar object
foo(3) '' creates a separate Bar object which is unused
print x.g(2.3) '' calls the Single overload of g on the Bar object and should print 1 + 5 + 2.3 = 8.3
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,5 @@
(defun accum (m)
(lambda (n)
(let ((sum (+ m n)))
`(#(func ,(accum sum))
#(sum ,sum)))))

View file

@ -0,0 +1,13 @@
(defun loop (m)
(receive
(`#(,caller ,n)
(let ((sum (+ m n)))
(! caller sum)
(loop sum)))))
(defun accum (m)
(let ((loop-pid (spawn (lambda () (loop m)))))
(lambda (n)
(! loop-pid `#(,(self) ,n))
(receive
(sum sum)))))

View file

@ -0,0 +1,13 @@
{
F Acc(start:Int) {
sum = start
F acc(i:Int) {
sum = sum + i
sum
}
}
acc = Acc(10)
echo(acc(5))
echo(acc(2))
}

View file

@ -0,0 +1,19 @@
proc accumulator(sum: float): auto =
var sum = sum
return proc (n: float): float =
sum += n
return sum
var x = accumulator(1)
echo x(5) # 6
echo x(2.3) # 8.3
var y = accumulator(1)
echo y(5) # 6
echo y(2.3) # 8.3
var z = accumulator(3)
echo z(5) # 8
echo z(2.3) # 10.3
echo x(0) # 8.3
echo z(0) # 10.3

View file

@ -0,0 +1,4 @@
: foo(n)
| ch |
Channel new dup ->ch send(n) drop
#[ ch receive swap + dup ch send drop ] ;

View file

@ -0,0 +1,9 @@
: testfoo
| x y z |
foo(1) ->x
5 x perform .
foo(3) ->y
2.3 x perform dup . ", x accumulator value is a " . class .cr
10 y perform dup . ", y accumulator value is a " . class .cr
foo("aaa") ->z
"bbb" z perform dup . ", z accumulator value is a " . class .cr ;

View file

@ -0,0 +1,22 @@
oGenerator = new Generator
Func main
oGenerator {
accumulator = generator(1)
see call accumulator(5)
see nl
generator(3)
see call accumulator(2.3)
}
Class Generator
aN = []
func generator i
aN + i
return eval(substr("return func d {
oGenerator {
aN[#id#] += d
return aN[#id#]
}
}","#id#",string(len(aN))))

View file

@ -0,0 +1,10 @@
class Accumulator(sum) {
method add(num) {
sum += num;
}
}
var x = Accumulator(1);
x.add(5);
Accumulator(3);
say x.add(2.3); # prints: 8.3

View file

@ -0,0 +1,8 @@
func Accumulator(sum) {
func(num) { sum += num };
}
var x = Accumulator(1);
x(5);
Accumulator(3);
say x(2.3); # prints: 8.3

View file

@ -0,0 +1,11 @@
func makeAccumulator(var sum: Double) -> Double -> Double {
return {
sum += $0
return sum
}
}
let x = makeAccumulator(1)
x(5)
let _ = makeAccumulator(3)
println(x(2.3))

View file

@ -0,0 +1,2 @@
def (accumulator n)
(fn() ++n)