top of page

Defining functions

A function can be defined using the def keyword followed by the name of the function and space-separated arguments.

​

def pow a b = a ^ b

 

def sqrt x = pow x 0.5

​

You can also define functions in the following way if the function takes only one argument

​

def area_of_circle radius (

return 3.14159 * radius ^ 2

)

​

def area_of_rect {length, width} (

length * width

)

​

If there is no return statement the last statement in the definition will get returned. 

bottom of page