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() {
function fs(Integer f(Integer n), {Integer*} s) => s.map(f);
function f1(Integer n) => n * 2;
function f2(Integer n) => n ^ 2;
value fsCurried = curry(fs);
value fsf1 = fsCurried(f1);
value fsf2 = fsCurried(f2);
value ints = 0..3;
print("fsf1(``ints``) is ``fsf1(ints)`` and fsf2(``ints``) is ``fsf2(ints)``");
value evens = (2..8).by(2);
print("fsf1(``evens``) is ``fsf1(evens)`` and fsf2(``evens``) is ``fsf2(evens)``");
}

View file

@ -0,0 +1,12 @@
(define $fs (map $1 $2))
(define $f1 (* $ 2))
(define $f2 (power $ 2))
(define $fsf1 (fs f1 $))
(define $fsf2 (fs f2 $))
(test (fsf1 {0 1 2 3}))
(test (fsf2 {0 1 2 3}))
(test (fsf1 {2 4 6 8}))
(test (fsf2 {2 4 6 8}))

View file

@ -0,0 +1,4 @@
{0 2 4 6}
{0 1 4 9}
{4 8 12 16}
{4 16 36 64}

View file

@ -0,0 +1,11 @@
fs = map
f1 = (* 2)
f2 = (^ 2)
fsf1 = fs.curry( f1 )
fsf2 = fs.curry( f2 )
println( fsf1(0..3) )
println( fsf2(0..3) )
println( fsf1(2..8 by 2) )
println( fsf2(2..8 by 2) )

View file

@ -0,0 +1,20 @@
(defun partial
"The partial function is arity 2 where the first parameter must be a
function and the second parameter may either be a single item or a list of
items.
When funcall is called against the result of the partial call, a second
parameter is applied to the partial function. This parameter too may be
either a single item or a list of items."
((func args-1) (when (is_list args-1))
(match-lambda
((args-2) (when (is_list args-2))
(apply func (++ args-1 args-2)))
((arg-2)
(apply func (++ args-1 `(,arg-2))))))
((func arg-1)
(match-lambda
((args-2) (when (is_list args-2))
(apply func (++ `(,arg-1) args-2)))
((arg-2)
(funcall func arg-1 arg-2)))))

View file

@ -0,0 +1,17 @@
(defun fs (f s) (lists:map f s))
(defun f1 (i) (* i 2))
(defun f2 (i) (math:pow i 2))
(set fsf1 (partial #'fs/2 #'f1/1))
(set fsf2 (partial #'fs/2 #'f2/1))
(set seq1 '((0 1 2 3)))
(set seq2 '((2 4 6 8)))
> (funcall fsf1 seq1)
(0 2 4 6)
> (funcall fsf2 seq1)
(0.0 1.0 4.0 9.0)
> (funcall fsf1 seq2)
(4 8 12 16)
> (funcall fsf2 seq2)
(4.0 16.0 36.0 64.0)

View file

@ -0,0 +1,6 @@
: fs(s, f) f s map ;
: f1 2 * ;
: f2 sq ;
#f1 #fs curry => fsf1
#f2 #fs curry => fsf2

View file

@ -0,0 +1,19 @@
func fs(f) {
func(*args) {
args.map {f(_)}
}
}
func double(n) { n * 2 };
func square(n) { n ** 2 };
var fs_double = fs(double);
var fs_square = fs(square);
var s = (0 .. 3);
say "fs_double(#{s}): #{fs_double(s...)}";
say "fs_square(#{s}): #{fs_square(s...)}";
s = [2, 4, 6, 8];
say "fs_double(#{s}): #{fs_double(s...)}";
say "fs_square(#{s}): #{fs_square(s...)}";