Call a function: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 4,391: | Line 4,391: | ||
* If no variable is specified, `put` prints the variable to stdout |
* If no variable is specified, `put` prints the variable to stdout |
||
<lang sensetalk>put zeroArgsFn() |
<lang sensetalk>put zeroArgsFn() |
||
// Function calls can also be made using the following syntax: |
|||
put the zeroArgsFn |
|||
function zeroArgsFn |
function zeroArgsFn |
||
Line 4,399: | Line 4,402: | ||
* Running a function requires a keyword such as `put; if no variable is return, put into e.g. _ |
* Running a function requires a keyword such as `put; if no variable is return, put into e.g. _ |
||
<lang sensetalk>put TwoArgFn("variable", (3, 4)) into _ |
<lang sensetalk>put TwoArgFn("variable", (3, 4)) into _ |
||
// Alternatively, the function can be called like so: |
|||
put the TwoArgFn of "variable", (3, 4) |
|||
// The parameter list is flexible, allowing any amount of variable to be passed in. |
// The parameter list is flexible, allowing any amount of variable to be passed in. |
||
// These can be accessed with the keyword `the parameterList` |
// These can be accessed with the keyword `the parameterList` |
||
// The specified parameters only limits to named parameters |
// The specified parameters only limits to named parameters |
||
get TwoArgFn("variable", (3, 4), "hello") |
|||
get the TwoArgFn of "variable", (3, 4), "hello" |
|||
function TwoArgFn arg1, arg2 |
function TwoArgFn arg1, arg2 |
||
Line 4,411: | Line 4,418: | ||
* A parameter is set to "" if nothing is specified |
* A parameter is set to "" if nothing is specified |
||
<lang sensetalk> |
<lang sensetalk>get ThreeArgFn("variable", (3, 4)) |
||
function ThreeArgFn arg1, arg2, arg3 |
function ThreeArgFn arg1, arg2, arg3 |
||
Line 4,418: | Line 4,425: | ||
* Using this, default parameter values can be set up if a check if done at the start of the function |
* Using this, default parameter values can be set up if a check if done at the start of the function |
||
<lang sensetalk> |
<lang sensetalk>get OneArgFn() -- arg1 is 5 |
||
get OneArgFn(10) -- arg1 is now 10 |
|||
function OneArgFn arg1 |
function OneArgFn arg1 |
||
Line 4,431: | Line 4,438: | ||
* If the argument prefixed by 'container', the variable is passed by reference |
* If the argument prefixed by 'container', the variable is passed by reference |
||
<lang sensetalk>put 3 into a |
<lang sensetalk>put 3 into a |
||
get AddOne(a) |
|||
put "Value of a = " & a |
put "Value of a = " & a |
||
// Value of a = 3 |
// Value of a = 3 |
||
put 5 into b |
put 5 into b |
||
get AddOne(container b) |
|||
put "Value of b = " & b |
put "Value of b = " & b |
||
// Value of b = 6 |
// Value of b = 6 |