Call a function: Difference between revisions

Z comes after P
(Z comes after P)
Line 15:
Note this task is about methods of calling functions, not methods of [[Function definition|defining functions]], which is a separate topic.
 
=={{header|ZX Spectrum Basic}}==
 
On the ZX Spectrum, functions and subroutines are separate entities. A function is limited to generating a return value. A subroutine can perform input and output.
 
<lang zxbasic>
10 REM functions cannot be called in statement context
20 PRINT FN a(5): REM The function is used in first class context
30 PRINT FN b(): REM Here we call a function that has no arguments
40 REM parameters cannot be passed parameters, however variables are global
50 LET n=1: REM This variable will be visible to the called subroutine
60 GOSUB 1000: REM subroutines are called by line number and do not have names
70 REM subroutines do not return a value, but we can see any variables it defined
80 REM subroutines cannot be used in first class context
90 REM builtin functions are used in first class context, and do not need the FN keyword prefix
100 PRINT SIN(50): REM here we pass a parameter to a builtin function
110 PRINT RND(): REM here we use a builtin function without parameters
</lang>
=={{header|Perl 6}}==
Fundamentally, nearly everything you do in Perl 6 is a function call if you look hard enough.
Line 149 ⟶ 132:
There is no difference between calling subroutines and functions in Perl 6, other than that
calling a function in void context that has no side effects is likely to get you a "Useless use of..." warning.
=={{header|ZX Spectrum Basic}}==
 
On the ZX Spectrum, functions and subroutines are separate entities. A function is limited to generating a return value. A subroutine can perform input and output.
 
<lang zxbasic>
10 REM functions cannot be called in statement context
20 PRINT FN a(5): REM The function is used in first class context
30 PRINT FN b(): REM Here we call a function that has no arguments
40 REM parameters cannot be passed parameters, however variables are global
50 LET n=1: REM This variable will be visible to the called subroutine
60 GOSUB 1000: REM subroutines are called by line number and do not have names
70 REM subroutines do not return a value, but we can see any variables it defined
80 REM subroutines cannot be used in first class context
90 REM builtin functions are used in first class context, and do not need the FN keyword prefix
100 PRINT SIN(50): REM here we pass a parameter to a builtin function
110 PRINT RND(): REM here we use a builtin function without parameters
</lang>
 
[[Category:Functions and subroutines]]
6,962

edits