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.




// Calling a function that requires no arguments
void foo() {puts("Calling a function with no arguments");}
foo();
 
// Calling a function with a fixed number of arguments
abs(-36);
 
// Calling a function with optional arguments
puts(nonewline: "nonewline is an optional argument");
puts("\n");
 
// Calling a function with a variable number of arguments
void var_arg_func(...args) {
    puts(length(args));
}
var_arg_func(1, 2);
var_arg_func(1, 2, 3);
 
// Obtaining the return value of a function
int s = clock("seconds"); //current time in seconds
// Calling a function with named arguments
// format is a named argument in Clock_format 
int str = Clock_format(s, format: "%B");
puts(str);
 
// Stating whether arguments are passed by value or by reference
void f(int a, int &b) { a++; b++; }
{
int a = 0;
int b = 0;
 
f(a, &b);
puts (a);
puts (b);
}