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*2+9

View file

@ -0,0 +1,3 @@
*[2;+[2;9]]
echo["Hello!"]
time[]

View file

@ -0,0 +1,2 @@
NOARG()
ARGS(1,5,42)

View file

@ -0,0 +1,3 @@
OPARG(1,2,3,4,5,6)
OPARG(1,2,3)
OPARG()

View file

@ -0,0 +1,2 @@
MATHS(2,4)→A
Disp GETSTR()

View file

@ -0,0 +1,2 @@
USER()
axeFunc()

View 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.
}

View file

@ -0,0 +1,2 @@
(defun my-func()
(: io format '"I get called with NOTHING!~n"))

View file

@ -0,0 +1,3 @@
> (my-func)
I get called with NOTHING!
ok

View file

@ -0,0 +1,2 @@
(defun my-func(a b)
(: io format '"I got called with ~p and ~p~n" (list a b)))

View file

@ -0,0 +1,3 @@
> (my-func '"bread" '"cheese")
I got called with "bread" and "cheese"
ok

View 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)))

View 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))

View file

@ -0,0 +1,4 @@
...
(cond ((== count limit) (hit-limit-func arg-1 arg-2))
((/= count limit) (keep-going-func count)))
...

View file

@ -0,0 +1,2 @@
> (>= 0.5 (: math sin 0.5))
true

View file

@ -0,0 +1,2 @@
(let ((x (: math sin 0.5)))
...)

View file

@ -0,0 +1,3 @@
foo()
-- or alternatively:
call(#foo, _movie)

View 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

View file

@ -0,0 +1,2 @@
put getAllUserFunctions()
-- [#sum, #double, #getAllUserFunctions]

View 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

View 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]

View file

@ -0,0 +1,3 @@
foo(1,2,3)
-- or alternatively:
call(#foo, _movie, 1, 2, 3)

View file

@ -0,0 +1,4 @@
on foo (a, b)
if voidP(b) then b = 1
return a * b
end

View file

@ -0,0 +1,4 @@
put foo(23, 2)
-- 46
put foo(23)
-- 23

View 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

View file

@ -0,0 +1,2 @@
put sum (1,2,3)
-- 6

View 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

View file

@ -0,0 +1,3 @@
l = [1,2,3]
put map(l, #doubleInt)
-- [2, 4, 6]

View file

@ -0,0 +1 @@
x = foo(1,2)

View 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);;

View 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

View file

@ -0,0 +1 @@
a b c f

View file

@ -0,0 +1 @@
f(a, b, c)

View file

@ -0,0 +1,4 @@
a b c f
a b f(c)
a f(b, c)
f(a, b, c)

View file

@ -0,0 +1 @@
a b c r m

View file

@ -0,0 +1 @@
r m(a, b, c)

View file

@ -0,0 +1 @@
{} = myfunction()

View file

@ -0,0 +1,4 @@
{cities,populations} = columize(muncipalities)
{{},populations} = columize(muncipalities) -- discard result[1]
{cities,{}} = columize(muncipalities) -- discard result[2]
{cities} = columize(muncipalities) -- ""

View 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"}

View file

@ -0,0 +1,2 @@
?myfunction(b:="then",a:=3) -- displays {3,"then"}
--?myfunction(b:="though") -- compile-time error

View file

@ -0,0 +1,2 @@
constant integer r_my_func = routine_id("myroutine")
?call_func(r_my_func,{1}) -- displays {1,"default"}

View file

@ -0,0 +1 @@
s = append(s,item)

View file

@ -0,0 +1,3 @@
hello()
func hello
see "Hello from function" + nl

View 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

View file

@ -0,0 +1,2 @@
sum(3,5) sum(1000,2000)
func sum x,y see x+y+nl

View 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

View file

@ -0,0 +1,4 @@
00110000000000100000000000000000 10. -12 to c
10110000000000000000000000000000 11. 13 to CI
11001111111111111111111111111111 12. -13
11001000000000000000000000000000 13. 19

View 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

View 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

View 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()

View 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