FratmScript 🤌🏻

Functions

facc name(params) { … } declares a function (function) and piglie value returns a value (return). Parameters can have a default (nome = "Gennà") and a rest (...numeri).

Short functions use arrows: n => n * 2, (a, b) => a + b, or with a block (x) => { … }. Functions are values: pass them around, return them, store them in variables.

facc saluta(nome = "Gennà") {
    piglie "Uè " + nome + "!"
}
stamm a dì(saluta())
stamm a dì(saluta("Totò"))

// Funzioni freccia e parametri rest
chist è doppio = n => n * 2
chist è somma = (...numeri) => numeri.reduce((totale, n) => totale + n, 0)
stamm a dì(doppio(21), somma(1, 2, 3))

// Una funzione che crea funzioni
facc contatore() {
    tien conto = 0
    piglie () => ++conto
}
chist è prossimo = contatore()
prossimo()
stamm a dì(prossimo())

Output

Uè Gennà!
Uè Totò!
42 6
2

Try this section in the playground