Making functions

Builtin functions

Rye comes with many builtin functions. Functions that are defined in a host language (Go).

Rye functions

You can create your own functions in Rye. To make a function you again use a function (that constructs functions). The simpler such builtin function is fn. It returns a function which we assign to a word using a set-word, like any other value.

double: fn { x } { x + x }

square: fn { y } { y * y }

Fn takes two blocks. First is called spec and is an argument list (and more), second is a block of code. Again value of the last expression is retuned, you don’t need to use return keyword.

We call them like we call builtin functions, by naming them and providing the arguments.

double 5
; returns: 10

square 5
; returns: 25