Declares the beginning of a function.
Function Identifier: ReturnType ( Parameters )
Statements...
End [ Function ]
The Function keyword begins the declaration of a function.
Please see the Functions section of the monkey language reference for more information on functions.
End
Language reference (Functions)
Language reference (Strict mode)
The Main function, required by all monkey programs.
Function
Main
()
Print
"Hello"
End
The closing keyword End may be replaced with End Function if preferred:
Function
Main
()
Print
"Hello"
End
Function
The Main function in Strict mode; requires Int return type and Return statement.
Strict
Function
Main
:
Int
()
Print
"Hello"
Return
0
End
A function that returns the result of adding two floating-point values.
Function
AddFloats
:
Float
(
value1
:
Float
,
value2
:
Float
)
Return
value1
+
value2
End
Print
AddFloats
(
1
,
2
)
For functions that don't return a value in Strict mode, the Void return type must be specified in the function declaration.
Strict
Function
PrintMessage
:
Void
(
message
:
String
)
Print
message
End