Call a function: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|C Sharp}}: Regularize header markup to recommended on category page) |
|||
Line 3,446: | Line 3,446: | ||
<pre> |
<pre> |
||
// Calling a function that requires no arguments |
// Calling a function that requires no arguments |
||
ModuleA ' introduce a namespace can have modules/functions/subs, anything inside, and threads. |
|||
ModuleA |
|||
Call FunctionA() ' introduce a namespace can have modules/functions/subs, anything inside. |
|||
Call FunctionA() |
|||
Call LambdaA() ' introduce a namespace can have modules/functions/subs, anything inside. |
|||
Call LambdaA() |
|||
SubAlfa() ' subroutine |
SubAlfa() ' subroutine this has the same scope as the caller, we can use Local statement to shadow variables/arrays |
||
Print @Simple() ' simple function |
Print @Simple() ' simple function this has the same scope as the caller, we can use Local statement to shadow variables/arrays |
||
Gosub labelA ' Statement Return used to return from a gosub, no arguments and no local statement used, the code is like any other code in the module/function/lambda scope. No jump out of scope allowed. |
|||
Gosub 10020 ' Statement Return used to return from a gosub,, no arguments and no local statement used, the code is like any other code in the module/function/lambda scope. No jump out of scope allowed. |
|||
// Calling a function with a fixed number of arguments |
// Calling a function with a fixed number of arguments |
||
ModuleA 100 |
ModuleA 100 |
||
Line 3,476: | Line 3,478: | ||
Print (lambda (x,y)->{=x**y}(2,3))*8=64 |
Print (lambda (x,y)->{=x**y}(2,3))*8=64 |
||
// Obtaining the return value of a function |
// Obtaining the return value of a function |
||
A%=FunctionA%() ' integer part from any numeric type. Also A% if get decimals convert to integer using school rounding (0.5, so 3.5 is 4, 2.5 is 3) |
|||
A=FunctionA() ' numeric or object |
A=FunctionA() ' numeric or object |
||
A$=FunctionA$() ' string or object which return string |
A$=FunctionA$() ' string or object which return string |
||
Line 3,508: | Line 3,511: | ||
Cube=A(3) : Square=A(2) |
Cube=A(3) : Square=A(2) |
||
Print Cube(2)=8, Square(2)=4 |
Print Cube(2)=8, Square(2)=4 |
||
OOP: Functions/Modules can be members of objects. |
|||
Objects may have a name (they live until code get out of scope) |
|||
Objects may don't have a name but one or more pointers, (they live until counting references are zero) |
|||
ObjectA.moduleA is a call to an object method (a module) |
|||
pointerA=>moduleA is a call to an object by a pointer |
|||
An object may return values, and may accept parameters too. Also objects if they didn't return values other than a copy of them can be use operators defined as object functions. |
|||
Objects may have events and fire them using Call Event "simpleevent", param1, param2... |
|||
Functions and lambda (not simple functions), and object functions can be passed by reference as parameters. |
|||
</pre> |
</pre> |
||