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.




void main() {
  // Function definition
  // See the "Function definition" task for more info
  void noArgs() {}
  void fixedArgs(int arg1, int arg2) {}
  void optionalArgs([int arg1 = 1]) {}
  void namedArgs({required int arg1}) {}
  int returnsValue() {return 1;}
 
  // Calling a function that requires no arguments
  noArgs();
 
  // Calling a function with a fixed number of arguments
  fixedArgs(1, 2);
 
  // Calling a function with optional arguments
  optionalArgs();
  optionalArgs(2);
 
  // Calling a function with named arguments
  namedArgs(arg1: 1);
 
  // Using a function in statement context
  if (true) {
    noArgs();
  }
 
  // Obtaining the return value of a function
  var value = returnsValue();
}