-
Notifications
You must be signed in to change notification settings - Fork 0
Functions
Sxtanna edited this page Jul 8, 2020
·
1 revision
fun 'name'{(arguments)}{: 'return type'} {
'function body'
{=> 'return expression'}
}
fun
- All functions start with the
fun
keyword.
- name
- Function names must follow
lowerCamelCase
naming standards.
- arguments (optional)
- Functions do not have to accept arguments, in which case parentheses can be omitted.
- Arguments of the same type that follow each other can have their type omitted until the last value.
- return type (optional)
- Functions do not have to return a value, in which case the type can be omitted.
- function body
- Function bodies can be entirely empty or contain any number of properties, expressions, and control flow.
- return expression
- Return expressions must be the final declaration of a function that returns a value, starting with
=>
function without arguments or a return value:
fun pushHelloWorld {
push "Hello World"
}
function with both arguments and a return value:
fun addTwoNumbers(arg0: Int, arg1: Int): Int {
=> arg0 + arg1
}
// can also be written as
fun addTwoNumbers(arg0, arg1: Int): Int {
=> arg0 + arg1
}