# Functions
Functions in Ride are defined with func
keyword. Functions must be defined before they are used.
A function must return a value. The function definition must have an expression to the right of the "=" sign. The return value is the expression result. There is no return
statement in Ride.
The return type is inferred automatically by the compiler.
# Examples
The say()
function without parameters returns the string Hello World!
:
func say() = {
"Hello world!"
}
Here is a function definition with three parameters:
func main(amount: Int, assetId: ByteVector|Unit, names: List[String]) = {
throw()
}
# Function call
Functions can be invoked in prefix and postfix order:
let list = [1, 2, 3]
let a1 = list.size()
let a2 = size(list)
let b1 = getInteger(this, “key”)
let b2 = this.getInteger(“key”)
In these examples a1
is the same as a2
and b1
is the same as b2
.
# Built-in Functions
The Standard library defines built-in functions that you can use in scripts.
# Annotations
In dApp scripts you can define callable functions and verifier function using annotations.