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 without arguments:
f()
 
; Call a function with a fixed number of arguments:
f("string", var, 15.5)
 
; Call a function with optional arguments:
f("string", var, 15.5)
 
; Call a function with a variable number of arguments:
f("string", var, 15.5)
 
; Call a function with named arguments:
    ; AutoHotkey does not have named arguments. However, in v1.1+,
    ; we can pass an object to the function:
f({named: "string", otherName: var, thirdName: 15.5})
 
; Use a function in statement context:
f(1), f(2) ; What is statement context?
 
; No first-class functions in AHK
 
; Obtaining the return value of a function:
varThatGetsReturnValue := f(1, "a")
 
; Cannot distinguish built-in functions
 
; Subroutines are called with GoSub; functions are called as above.
; Subroutines cannot be passed variables
 
; Stating whether arguments are passed by value or by reference:
; [v1.1.01+]: The IsByRef() function can be used to determine
;     whether the caller supplied a variable for a given ByRef parameter.
; A variable cannot be passed by value to a byRef parameter. Instead, do this:
f(tmp := varIdoNotWantChanged)
; the function f will receive the value of varIdoNotWantChanged, but any
; modifications will be made to the variable tmp.
 
; Partial application is impossible.
 