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.




procedure main()  # demonstrate and describe function calling syntax and semantics
 
   # normal procedure/function calling
 
   f()                      # no arguments, also command context
   f(x)                     # fixed number of arguments
   f(x,h,w)                 # variable number of arguments (varargs)
   y := f(x)                # Obtaining the returned value of a function
 
   # procedures as first class values and string invocation 
 
   f!L                      # Alternate calling syntax using a list as args   
   (if \x then f else g)()  # call (f or g)()
   f := write               # assign a procedure
   f("Write is now called") # ... and call it
   "f"()                    # string invocation, procedure
   "-"(1)                   # string invocation, operator
 
   # Co-expressions
 
   f{e1,e2}                 # parallel evaluation co-expression call  
                            # equivalent to f([create e1, create e2]) 
   expr @ coexp             # transmission of a single value to a coexpression
   [e1,e2]@coexp            # ... of multiple values (list) to a coexpression 
   coexp(e1,e2)             # ... same as above but only in Unicon 
 
   # Other
 
   f("x:=",1,"y:=",2)       # named parameters (user defined)
end