Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
1
Task/Call-a-function/AntLang/call-a-function-1.antlang
Normal file
1
Task/Call-a-function/AntLang/call-a-function-1.antlang
Normal file
|
|
@ -0,0 +1 @@
|
|||
2*2+9
|
||||
3
Task/Call-a-function/AntLang/call-a-function-2.antlang
Normal file
3
Task/Call-a-function/AntLang/call-a-function-2.antlang
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
*[2;+[2;9]]
|
||||
echo["Hello!"]
|
||||
time[]
|
||||
2
Task/Call-a-function/Axe/call-a-function-1.axe
Normal file
2
Task/Call-a-function/Axe/call-a-function-1.axe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
NOARG()
|
||||
ARGS(1,5,42)
|
||||
3
Task/Call-a-function/Axe/call-a-function-2.axe
Normal file
3
Task/Call-a-function/Axe/call-a-function-2.axe
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
OPARG(1,2,3,4,5,6)
|
||||
OPARG(1,2,3)
|
||||
OPARG()
|
||||
2
Task/Call-a-function/Axe/call-a-function-3.axe
Normal file
2
Task/Call-a-function/Axe/call-a-function-3.axe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
MATHS(2,4)→A
|
||||
Disp GETSTR()
|
||||
2
Task/Call-a-function/Axe/call-a-function-4.axe
Normal file
2
Task/Call-a-function/Axe/call-a-function-4.axe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
USER()
|
||||
axeFunc()
|
||||
5
Task/Call-a-function/I/call-a-function.i
Normal file
5
Task/Call-a-function/I/call-a-function.i
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
software {
|
||||
var line = read() //Calling a function with no arguments and getting a return value.
|
||||
var t = text(10) //Calling a function with fixed arguments.
|
||||
print(1,2,3,4,5,6,7,8,9,0,line,t) //Calling a variadic function.
|
||||
}
|
||||
2
Task/Call-a-function/LFE/call-a-function-1.lfe
Normal file
2
Task/Call-a-function/LFE/call-a-function-1.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(defun my-func()
|
||||
(: io format '"I get called with NOTHING!~n"))
|
||||
3
Task/Call-a-function/LFE/call-a-function-2.lfe
Normal file
3
Task/Call-a-function/LFE/call-a-function-2.lfe
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> (my-func)
|
||||
I get called with NOTHING!
|
||||
ok
|
||||
2
Task/Call-a-function/LFE/call-a-function-3.lfe
Normal file
2
Task/Call-a-function/LFE/call-a-function-3.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(defun my-func(a b)
|
||||
(: io format '"I got called with ~p and ~p~n" (list a b)))
|
||||
3
Task/Call-a-function/LFE/call-a-function-4.lfe
Normal file
3
Task/Call-a-function/LFE/call-a-function-4.lfe
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> (my-func '"bread" '"cheese")
|
||||
I got called with "bread" and "cheese"
|
||||
ok
|
||||
14
Task/Call-a-function/LFE/call-a-function-5.lfe
Normal file
14
Task/Call-a-function/LFE/call-a-function-5.lfe
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(defmodule args
|
||||
(export all))
|
||||
|
||||
(defun my-func ()
|
||||
(my-func () () ()))
|
||||
|
||||
(defun my-func (a)
|
||||
(my-func a () ()))
|
||||
|
||||
(defun my-func (a b)
|
||||
(my-func a b ()))
|
||||
|
||||
(defun my-func (a b c)
|
||||
(: io format '"~p ~p ~p~n" (list a b c)))
|
||||
16
Task/Call-a-function/LFE/call-a-function-6.lfe
Normal file
16
Task/Call-a-function/LFE/call-a-function-6.lfe
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
> (slurp '"args.lfe")
|
||||
#(ok args)
|
||||
> (my-func)
|
||||
[] [] []
|
||||
ok
|
||||
> (my-func '"apple")
|
||||
"apple" [] []
|
||||
ok
|
||||
> (my-func '"apple" '"banana")
|
||||
"apple" "banana" []
|
||||
ok
|
||||
> (my-func '"apple" '"banana" '"cranberry")
|
||||
"apple" "banana" "cranberry"
|
||||
ok
|
||||
> (my-func '"apple" '"banana" '"cranberry" '"bad arg")
|
||||
exception error: #(unbound_func #(my-func 4))
|
||||
4
Task/Call-a-function/LFE/call-a-function-7.lfe
Normal file
4
Task/Call-a-function/LFE/call-a-function-7.lfe
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
...
|
||||
(cond ((== count limit) (hit-limit-func arg-1 arg-2))
|
||||
((/= count limit) (keep-going-func count)))
|
||||
...
|
||||
2
Task/Call-a-function/LFE/call-a-function-8.lfe
Normal file
2
Task/Call-a-function/LFE/call-a-function-8.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> (>= 0.5 (: math sin 0.5))
|
||||
true
|
||||
2
Task/Call-a-function/LFE/call-a-function-9.lfe
Normal file
2
Task/Call-a-function/LFE/call-a-function-9.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(let ((x (: math sin 0.5)))
|
||||
...)
|
||||
3
Task/Call-a-function/Lingo/call-a-function-1.lingo
Normal file
3
Task/Call-a-function/Lingo/call-a-function-1.lingo
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
foo()
|
||||
-- or alternatively:
|
||||
call(#foo, _movie)
|
||||
17
Task/Call-a-function/Lingo/call-a-function-10.lingo
Normal file
17
Task/Call-a-function/Lingo/call-a-function-10.lingo
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
on getAllUserFunctions ()
|
||||
res = []
|
||||
repeat with i = 1 to _movie.castlib.count
|
||||
c = _movie.castlib(i)
|
||||
repeat with j = 1 to c.member.count
|
||||
m = c.member[j]
|
||||
if m.type<>#script then next repeat
|
||||
if m.scripttype=#movie then
|
||||
functions = m.script.handlers()
|
||||
repeat with f in functions
|
||||
res.append(f)
|
||||
end repeat
|
||||
end if
|
||||
end repeat
|
||||
end repeat
|
||||
return res
|
||||
end
|
||||
2
Task/Call-a-function/Lingo/call-a-function-11.lingo
Normal file
2
Task/Call-a-function/Lingo/call-a-function-11.lingo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
put getAllUserFunctions()
|
||||
-- [#sum, #double, #getAllUserFunctions]
|
||||
6
Task/Call-a-function/Lingo/call-a-function-12.lingo
Normal file
6
Task/Call-a-function/Lingo/call-a-function-12.lingo
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
on double (someList)
|
||||
cnt = someList.count
|
||||
repeat with i = 1 to cnt
|
||||
someList[i] = someList[i] * 2
|
||||
end repeat
|
||||
end
|
||||
9
Task/Call-a-function/Lingo/call-a-function-13.lingo
Normal file
9
Task/Call-a-function/Lingo/call-a-function-13.lingo
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
l = [1,2,3]
|
||||
double(l)
|
||||
put l
|
||||
-- [2, 4, 6]
|
||||
|
||||
l = [1,2,3]
|
||||
double(l.duplicate())
|
||||
put l
|
||||
-- [1, 2, 3]
|
||||
3
Task/Call-a-function/Lingo/call-a-function-2.lingo
Normal file
3
Task/Call-a-function/Lingo/call-a-function-2.lingo
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
foo(1,2,3)
|
||||
-- or alternatively:
|
||||
call(#foo, _movie, 1, 2, 3)
|
||||
4
Task/Call-a-function/Lingo/call-a-function-3.lingo
Normal file
4
Task/Call-a-function/Lingo/call-a-function-3.lingo
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
on foo (a, b)
|
||||
if voidP(b) then b = 1
|
||||
return a * b
|
||||
end
|
||||
4
Task/Call-a-function/Lingo/call-a-function-4.lingo
Normal file
4
Task/Call-a-function/Lingo/call-a-function-4.lingo
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
put foo(23, 2)
|
||||
-- 46
|
||||
put foo(23)
|
||||
-- 23
|
||||
7
Task/Call-a-function/Lingo/call-a-function-5.lingo
Normal file
7
Task/Call-a-function/Lingo/call-a-function-5.lingo
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
on sum ()
|
||||
res = 0
|
||||
repeat with i = 1 to the paramCount
|
||||
res = res + param(i)
|
||||
end repeat
|
||||
return res
|
||||
end
|
||||
2
Task/Call-a-function/Lingo/call-a-function-6.lingo
Normal file
2
Task/Call-a-function/Lingo/call-a-function-6.lingo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
put sum (1,2,3)
|
||||
-- 6
|
||||
20
Task/Call-a-function/Lingo/call-a-function-7.lingo
Normal file
20
Task/Call-a-function/Lingo/call-a-function-7.lingo
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
----------------------------------------
|
||||
-- One of the five native iterative methods defined in ECMAScript 5
|
||||
-- @param {list} tList
|
||||
-- @param {symbol} cbFunc
|
||||
-- @param {object} [cbObj=_movie]
|
||||
-- @return {list}
|
||||
----------------------------------------
|
||||
on map (tList, cbFunc, cbObj)
|
||||
if voidP(cbObj) then cbObj = _movie
|
||||
res = []
|
||||
cnt = tList.count
|
||||
repeat with i = 1 to cnt
|
||||
res[i] = call(cbFunc, cbObj, tList[i], i, tList)
|
||||
end repeat
|
||||
return res
|
||||
end
|
||||
|
||||
on doubleInt (n)
|
||||
return n*2
|
||||
end
|
||||
3
Task/Call-a-function/Lingo/call-a-function-8.lingo
Normal file
3
Task/Call-a-function/Lingo/call-a-function-8.lingo
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
l = [1,2,3]
|
||||
put map(l, #doubleInt)
|
||||
-- [2, 4, 6]
|
||||
1
Task/Call-a-function/Lingo/call-a-function-9.lingo
Normal file
1
Task/Call-a-function/Lingo/call-a-function-9.lingo
Normal file
|
|
@ -0,0 +1 @@
|
|||
x = foo(1,2)
|
||||
43
Task/Call-a-function/Luck/call-a-function.luck
Normal file
43
Task/Call-a-function/Luck/call-a-function.luck
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* Calling a function that requires no arguments */
|
||||
f();;
|
||||
|
||||
/* Calling a function with a fixed number of arguments */
|
||||
f(1,2);;
|
||||
|
||||
/* Calling a function with optional arguments
|
||||
Note: defining the function is cumbersome but will get easier in future versions. */
|
||||
f(1,2,new {default with x=3, y=4});;
|
||||
|
||||
/* Calling a function with a variable number of arguments */
|
||||
printf("%d %d %d %d":char*,2,3,4,5);;
|
||||
|
||||
/* Calling a function with named arguments
|
||||
Note: may get syntax sugar in future versions */
|
||||
f(1,2,new {default with x=3, y=4});;
|
||||
|
||||
/* Using a function in statement context (what?) */
|
||||
f();f();f();;
|
||||
|
||||
/* Using a function in first-class context within an expression */
|
||||
[1,2,3].map(string);;
|
||||
|
||||
/* Obtaining the return value of a function */
|
||||
let x:int = f();;
|
||||
|
||||
/* Distinguishing built-in functions and user-defined functions */
|
||||
/* Builtin function i.e. custom calling convention: */
|
||||
(@ binop "==" l r);;
|
||||
/* User defined function i.e. normal function */
|
||||
f(l)(r);;
|
||||
|
||||
/* Distinguishing subroutines and functions: both are supported, but compiler is not aware of difference */
|
||||
sub();;
|
||||
fun();;
|
||||
|
||||
/* Stating whether arguments are passed by value or by reference */
|
||||
f(value);; /* by value */
|
||||
f(&value);; /* by pointer reference */
|
||||
f(ref(value));; /* by managed reference */
|
||||
|
||||
/* Is partial application possible and how */
|
||||
tasty_curry(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z);;
|
||||
43
Task/Call-a-function/Nim/call-a-function.nim
Normal file
43
Task/Call-a-function/Nim/call-a-function.nim
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
proc no_args() =
|
||||
discard
|
||||
# call
|
||||
no_args()
|
||||
|
||||
proc fixed_args(x, y) =
|
||||
echo x
|
||||
echo y
|
||||
# calls
|
||||
fixed_args(1, 2) # x=1, y=2
|
||||
fixed_args 1, 2 # same call
|
||||
1.fixed_args(2) # same call
|
||||
|
||||
|
||||
proc opt_args(x=1.0) =
|
||||
echo x
|
||||
# calls
|
||||
opt_args() # 1
|
||||
opt_args(3.141) # 3.141
|
||||
|
||||
proc var_args(v: varargs[string, `$`]) =
|
||||
for x in v: echo x
|
||||
# calls
|
||||
var_args(1, 2, 3) # (1, 2, 3)
|
||||
var_args(1, (2,3)) # (1, (2, 3))
|
||||
var_args() # ()
|
||||
|
||||
## Named arguments
|
||||
fixed_args(y=2, x=1) # x=1, y=2
|
||||
|
||||
## As a statement
|
||||
if true:
|
||||
no_args()
|
||||
|
||||
proc return_something(x): int =
|
||||
x + 1
|
||||
|
||||
var a = return_something(2)
|
||||
|
||||
## First-class within an expression
|
||||
let x = return_something(19) + 10
|
||||
let y = 19.return_something() + 10
|
||||
let z = 19.return_something + 10
|
||||
1
Task/Call-a-function/Oforth/call-a-function-1.oforth
Normal file
1
Task/Call-a-function/Oforth/call-a-function-1.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
a b c f
|
||||
1
Task/Call-a-function/Oforth/call-a-function-2.oforth
Normal file
1
Task/Call-a-function/Oforth/call-a-function-2.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
f(a, b, c)
|
||||
4
Task/Call-a-function/Oforth/call-a-function-3.oforth
Normal file
4
Task/Call-a-function/Oforth/call-a-function-3.oforth
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
a b c f
|
||||
a b f(c)
|
||||
a f(b, c)
|
||||
f(a, b, c)
|
||||
1
Task/Call-a-function/Oforth/call-a-function-4.oforth
Normal file
1
Task/Call-a-function/Oforth/call-a-function-4.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
a b c r m
|
||||
1
Task/Call-a-function/Oforth/call-a-function-5.oforth
Normal file
1
Task/Call-a-function/Oforth/call-a-function-5.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
r m(a, b, c)
|
||||
1
Task/Call-a-function/Phix/call-a-function-1.phix
Normal file
1
Task/Call-a-function/Phix/call-a-function-1.phix
Normal file
|
|
@ -0,0 +1 @@
|
|||
{} = myfunction()
|
||||
4
Task/Call-a-function/Phix/call-a-function-2.phix
Normal file
4
Task/Call-a-function/Phix/call-a-function-2.phix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{cities,populations} = columize(muncipalities)
|
||||
{{},populations} = columize(muncipalities) -- discard result[1]
|
||||
{cities,{}} = columize(muncipalities) -- discard result[2]
|
||||
{cities} = columize(muncipalities) -- ""
|
||||
6
Task/Call-a-function/Phix/call-a-function-3.phix
Normal file
6
Task/Call-a-function/Phix/call-a-function-3.phix
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
function myfunction(integer a, string b="default")
|
||||
return {a,b}
|
||||
end function
|
||||
--? myfunction() -- illegal, compile-time error
|
||||
?myfunction(1) -- displays {1,"default"}
|
||||
?myfunction(2,"that") -- displays {2,"that"}
|
||||
2
Task/Call-a-function/Phix/call-a-function-4.phix
Normal file
2
Task/Call-a-function/Phix/call-a-function-4.phix
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
?myfunction(b:="then",a:=3) -- displays {3,"then"}
|
||||
--?myfunction(b:="though") -- compile-time error
|
||||
2
Task/Call-a-function/Phix/call-a-function-5.phix
Normal file
2
Task/Call-a-function/Phix/call-a-function-5.phix
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
constant integer r_my_func = routine_id("myroutine")
|
||||
?call_func(r_my_func,{1}) -- displays {1,"default"}
|
||||
1
Task/Call-a-function/Phix/call-a-function-6.phix
Normal file
1
Task/Call-a-function/Phix/call-a-function-6.phix
Normal file
|
|
@ -0,0 +1 @@
|
|||
s = append(s,item)
|
||||
3
Task/Call-a-function/Ring/call-a-function-1.ring
Normal file
3
Task/Call-a-function/Ring/call-a-function-1.ring
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
hello()
|
||||
func hello
|
||||
see "Hello from function" + nl
|
||||
3
Task/Call-a-function/Ring/call-a-function-2.ring
Normal file
3
Task/Call-a-function/Ring/call-a-function-2.ring
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
first() second()
|
||||
func first see "message from the first function" + nl
|
||||
func second see "message from the second function" + nl
|
||||
2
Task/Call-a-function/Ring/call-a-function-3.ring
Normal file
2
Task/Call-a-function/Ring/call-a-function-3.ring
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
sum(3,5) sum(1000,2000)
|
||||
func sum x,y see x+y+nl
|
||||
4
Task/Call-a-function/Ring/call-a-function-4.ring
Normal file
4
Task/Call-a-function/Ring/call-a-function-4.ring
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# this program will print the hello world message first then execute the main function
|
||||
See "Hello World!" + nl
|
||||
func main
|
||||
see "Message from the main function" + nl
|
||||
4
Task/Call-a-function/SSEM/call-a-function.ssem
Normal file
4
Task/Call-a-function/SSEM/call-a-function.ssem
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
00110000000000100000000000000000 10. -12 to c
|
||||
10110000000000000000000000000000 11. 13 to CI
|
||||
11001111111111111111111111111111 12. -13
|
||||
11001000000000000000000000000000 13. 19
|
||||
10
Task/Call-a-function/Sidef/call-a-function-1.sidef
Normal file
10
Task/Call-a-function/Sidef/call-a-function-1.sidef
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
foo(); # without arguments
|
||||
foo(1, 2); # with two arguments
|
||||
foo(args...); # with a variable number of arguments
|
||||
foo(name: 'Bar', age: 42); # with named arguments
|
||||
|
||||
var f = foo; # store the function foo inside 'f'
|
||||
var result = f(); # obtain the return value of a function
|
||||
|
||||
var arr = [1,2,3];
|
||||
foo(arr); # the arguments are passed by object-reference
|
||||
12
Task/Call-a-function/Sidef/call-a-function-2.sidef
Normal file
12
Task/Call-a-function/Sidef/call-a-function-2.sidef
Normal 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
|
||||
35
Task/Call-a-function/Swift/call-a-function.swift
Normal file
35
Task/Call-a-function/Swift/call-a-function.swift
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// call a function with no args
|
||||
noArgs()
|
||||
|
||||
// call a function with one arg with no external name
|
||||
oneArgUnnamed(1)
|
||||
|
||||
// call a function with one arg with external name
|
||||
oneArgNamed(arg: 1)
|
||||
|
||||
// call a function with two args with no external names
|
||||
twoArgsUnnamed(1, 2)
|
||||
|
||||
// call a function with two args and external names
|
||||
twoArgsNamed(arg1: 1, arg2: 2)
|
||||
|
||||
// call a function with an optional arg
|
||||
// with arg
|
||||
optionalArguments(arg: 1)
|
||||
// without
|
||||
optionalArguments() // defaults to 0
|
||||
|
||||
// function that takes another function as arg
|
||||
funcArg(noArgs)
|
||||
|
||||
// variadic function
|
||||
variadic(opts: "foo", "bar")
|
||||
|
||||
// getting a return value
|
||||
let foo = returnString()
|
||||
|
||||
// getting a bunch of return values
|
||||
let (foo, bar, baz) = returnSomeValues()
|
||||
|
||||
// getting a bunch of return values, discarding second returned value
|
||||
let (foo, _, baz) = returnSomeValues()
|
||||
19
Task/Call-a-function/XLISP/call-a-function.xlisp
Normal file
19
Task/Call-a-function/XLISP/call-a-function.xlisp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
; call a function (procedure) with no arguments:
|
||||
(foo)
|
||||
|
||||
; call a function (procedure) with arguments:
|
||||
(foo bar baz)
|
||||
; the first symbol after "(" is the name of the function
|
||||
; the other symbols are the arguments
|
||||
|
||||
; call a function on a list of arguments formed at run time:
|
||||
(apply foo bar)
|
||||
|
||||
; In a REPL, the return value will be printed.
|
||||
; In other contexts, it can be fed as argument into a further function:
|
||||
(foo (bar baz))
|
||||
; this calls bar on the argument baz and then calls foo on the return value
|
||||
|
||||
; or it can simply be discarded
|
||||
(foo bar)
|
||||
; nothing is done with the return value
|
||||
Loading…
Add table
Add a link
Reference in a new issue