RosettaCodeData/Task/Call-a-function/Luck/call-a-function.luck

44 lines
1.4 KiB
Plaintext

/* 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);;