Call a function: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 2,394: | Line 2,394: | ||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
==Standard Call of Modules/Functions== |
|||
In M2000 we can use arrays, functions and subroutines with same name. Using @ we can direct interpreter to use function. Using Gosub we direct interpreter to call a subroutine. These happen at module/function level. |
In M2000 we can use arrays, functions and subroutines with same name. Using @ we can direct interpreter to use function. Using Gosub we direct interpreter to call a subroutine. These happen at module/function level. |
||
A Subroutine is code inside Modules/Functions where all definitions in module/function are visible. Modules and functions can call own modules/functions or global modules/functions. Functions can use recursion. Module with standard calling can't use recursion (need to use Call nameOfModule to call itself). |
|||
<lang M2000 Interpreter> |
<lang M2000 Interpreter> |
||
Line 2,425: | Line 2,428: | ||
Call Void CheckIt() |
Call Void CheckIt() |
||
Call Void Function Checkit |
Call Void Function Checkit |
||
\\ subs are part of modules/functions (there are no global subs, but there is a way to share definitions modules from parent module). |
|||
Module CheckSub { |
|||
M=1 |
|||
a(100) ' 400 |
|||
a(100) ' 800 |
|||
Module Child { |
|||
M=1 |
|||
a(100) ' 400 |
|||
a(100) ' 800 |
|||
} |
|||
Child |
|||
Sub a(x) |
|||
b(x*4) |
|||
M++ |
|||
End Sub |
|||
Sub b(x) |
|||
Print x*M |
|||
End Sub |
|||
} |
|||
CheckSub |
|||
</lang> |
</lang> |
||
Line 2,477: | Line 2,501: | ||
Print M=12 |
Print M=12 |
||
</lang> |
</lang> |
||
=={{header|Maple}}== |
=={{header|Maple}}== |