Task

Demonstrate the different syntax and semantics provided for calling a function.



This may include:

   Calling a function that requires no arguments
   Calling a function with a fixed number of arguments
   Calling a function with optional arguments
   Calling a function with a variable number of arguments
   Calling a function with named arguments
   Using a function in statement context
   Using a function in first-class context within an expression
   Obtaining the return value of a function
   Distinguishing built-in functions and user-defined functions
   Distinguishing subroutines and functions
   Stating whether arguments are passed by value or by reference
   Is partial application possible and how


This task is not about defining functions.




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