Jump to content

Call a function: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 4,391:
* If no variable is specified, `put` prints the variable to stdout
<lang sensetalk>put zeroArgsFn()
 
// Function calls can also be made using the following syntax:
put the zeroArgsFn
 
function zeroArgsFn
Line 4,399 ⟶ 4,402:
* 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 _
 
// 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.
// These can be accessed with the keyword `the parameterList`
// The specified parameters only limits to named parameters
putget TwoArgFn("variable", (3, 4), "hello") into _
get the TwoArgFn of "variable", (3, 4), "hello"
 
function TwoArgFn arg1, arg2
Line 4,411 ⟶ 4,418:
 
* A parameter is set to "" if nothing is specified
<lang sensetalk>putget ThreeArgFn("variable", (3, 4)) into _
 
function ThreeArgFn arg1, arg2, arg3
Line 4,418 ⟶ 4,425:
 
* Using this, default parameter values can be set up if a check if done at the start of the function
<lang sensetalk>putget OneArgFn() into _ -- arg1 is 5
putget OneArgFn(10) into _ -- arg1 is now 10
 
function OneArgFn arg1
Line 4,431 ⟶ 4,438:
* If the argument prefixed by 'container', the variable is passed by reference
<lang sensetalk>put 3 into a
putget AddOne(a) into _
put "Value of a = " & a
// Value of a = 3
 
put 5 into b
putget AddOne(container b) into _
put "Value of b = " & b
// Value of b = 6
Cookies help us deliver our services. By using our services, you agree to our use of cookies.