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 - Liberty BASIC
 
'First, function result could not be discarded
' that is, you cannot do "f(x)" as a separate statement
 
'Calling a function that requires no arguments
res = f()   'brackets required
 
'Calling a function with a fixed number of arguments
res = g(x)
res = h(x,y)
'Calling a function with optional arguments
    'impossible for user-defined functions
    'Some build-in functions ex. INSTR and MID$ could be called with last argument omitted
'Calling a function with a variable number of arguments
    'impossible
'Calling a function with named arguments
    'impossible
'Using a function in statement context
    'impossible (see starting notice)
'Using a function in first-class context within an expression
    'impossible
'Obtaining the return value of a function
res = g(x)
'Distinguishing built-in functions and user-defined functions
    'I would say impossible. Though built-in functions could be EVAL'ed,
    'while user-defined would not be called (tries address array instead).
    'Still cannot distinguish user-defined function from array.
'Distinguishing subroutines and functions
    'then defined, subroutines and functions defined with words
    'SUB and FUNCTION (case incensitive)
    'Then used, function used as expression (with return value),
    res = g(x)
    'while subroutines called with special keyword CALL and without brackets
    call test x, y
'Stating whether arguments are passed by value or by reference
    'Variables passed as arguments into functions and subs are passed "by value" by default
    'parameters could be passed "by reference" if formal parameter in sub/function definition uses the "byref" specifier
    'Then calling a function, you can prevent pass by reference by changing variable to expression
    '   like x+0, x$+"" or just (x), (x$)
'Is partial application possible and how
    'impossible
 