Call a function: Difference between revisions

Liberty BASIC added.
(Liberty BASIC added.)
Line 610:
var foo = [1, 2, 3];
mutate(foo) // foo is now [null, 2, 3], not 42</lang>
 
=={{header|Liberty BASIC}}==
<lang lb>
'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
</lang>
 
=={{header|LFE}}==
Anonymous user