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,3 @@
[ 1 , 2, 3 ]
' n:sqr
a:map

View file

@ -0,0 +1,24 @@
PROGRAM CALLBACK
!
! for rosettacode.org
!
DIM A[5]
FUNCTION CBACK(X)
CBACK=2*X-1
END FUNCTION
PROCEDURE PROCMAP(ZETA,DUMMY(X)->OUTP)
OUTP=DUMMY(ZETA)
END PROCEDURE
BEGIN
A[1]=1 A[2]=2 A[3]=3 A[4]=4 A[5]=5
FOR I%=1 TO 5 DO
PROCMAP(A[I%],CBACK(X)->OUTP)
PRINT(OUTP;)
END FOR
PRINT
END PROGRAM

View file

@ -0,0 +1,11 @@
(vector-map sqrt #(0 4 16 49))
→ #( 0 2 4 7)
;; or
(map exp #(0 1 2))
→ #( 1 2.718281828459045 7.38905609893065)
;; or
(for/vector ([elem #(2 3 4)] [i (in-naturals)]) (printf "v[%d] = %a" i elem) (* elem elem))
v[0] = 2
v[1] = 3
v[2] = 4
→ #( 4 9 16)

View file

@ -0,0 +1,19 @@
' FB 1.05.0 Win64
Sub PrintEx(n As Integer)
Print n, n * n, n * n * n
End Sub
Sub Proc(a() As Integer, callback As Sub(n As Integer))
For i As Integer = LBound(a) To UBound(a)
callback(i)
Next
End Sub
Dim a(1 To 10) As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Print " n", "n^2", "n^3"
Print " -", "---", "---"
Proc(a(), @PrintEx)
Print
Print "Press any key to quit the program"
Sleep

View file

@ -0,0 +1,3 @@
[1, 2, 3].foreach( println )
[1, 2, 3].foreach( a -> println(2a) )

View file

@ -0,0 +1,12 @@
define cube(n::integer) => #n*#n*#n
local(
mynumbers = array(1, 2, 3, 4, 5),
mycube = array
)
#mynumbers -> foreach => {
#mycube -> insert(cube(#1))
}
#mycube

View file

@ -0,0 +1,3 @@
{
[1, 2, 3, 4, 5].map(F(x) x*x)
}

View file

@ -0,0 +1,2 @@
var arr = [1,2,3,4]
arr.map proc(some: var int) = echo(some, " squared = ", some*some)

View file

@ -0,0 +1 @@
0 #+ [ 1, 2, 3, 4, 5 ] apply

View file

@ -0,0 +1 @@
#sq [ 1, 2, 3, 4, 5 ] map

View file

@ -0,0 +1,13 @@
function apply(integer f, sequence s)
-- apply function f to all elements of sequence s
for i = 1 to length(s) do
s[i] = call_func(f, {s[i]})
end for
return s
end function
function add1(integer x)
return x + 1
end function
? apply(routine_id("add1"),{1,2,3})

View file

@ -0,0 +1,3 @@
for x in [1,2,3,4,5]
x = x*x
next

View file

@ -0,0 +1 @@
func callback(i) { say i**2 };

View file

@ -0,0 +1 @@
[1,2,3,4].each(callback);

View file

@ -0,0 +1 @@
[1,2,3,4].each{|i| say i**2 };

View file

@ -0,0 +1 @@
[1,2,3,4,5].map{|i| i**2 };

View file

@ -0,0 +1,4 @@
let numbers = { 1, 2, 3, 4 };
foreach(numbers, function(idx, num) {
print(num);
});

View file

@ -0,0 +1,4 @@
let dict = { "foo": 42, "bar": 13, "baz": 37 };
let doubled = map(dict, function(key, val) {
return val * 2;
});

View file

@ -0,0 +1,13 @@
func square(n: Int) -> Int {
return n * n
}
let numbers = [1, 3, 5, 7]
let squares1a = numbers.map(square) // map method on array
let squares1b = numbers.map {x in x*x} // map method on array with anonymous function
let squares1b = numbers.map { $0 * $0 } // map method on array with anonymous function and unnamed parameters
let isquares1 = numbers.lazy.map(square) // lazy sequence

View file

@ -0,0 +1 @@
map prn '(1 2 3 4 5)

View file

@ -0,0 +1,4 @@
var arr = [1, 2, 3, 4, 5]
arr = arr.map { |x| x * 2 }.toList
arr = arr.map(Fn.new {|x| x / 2}).toList
arr.each {|x| System.print(x) }

View file

@ -0,0 +1,14 @@
# Illustration of map/1 using the builtin filter: exp
map(exp) # exponentiate each item in the input list
# A compound expression can be specified as the argument to map, e.g.
map( (. * .) + sqrt ) # x*x + sqrt(x)
# The compound expression can also be a composition of filters, e.g.
map( sqrt|floor ) # the floor of the sqrt
# Array comprehension
reduce .[] as $n ([]; . + [ exp ])
# Elementwise operation
[.[] + 1 ] # add 1 to each element of the input array

View file

@ -0,0 +1,3 @@
$ jq -c ' [.[] + 1 ]'
[0, 1 , 10]
[1,2,11]