Skip to content

Parameters

Each parameter declares its type before the name.

numero sumar(numero a, numero b) {
retornar a + b
}

Use var to allow the parameter to be modified within the function. The change does not affect the original argument because Quetzal evaluates arguments by value.

texto formatear(texto var mensaje) {
mensaje = mensaje.recortar()
mensaje = mensaje.titulo()
retornar mensaje
}

You can receive typed lists, generic lists, or jsn values.

numero promedio_lista(lista<numero> valores) {
retornar valores.promedio()
}
texto obtener_nombre(jsn datos) {
retornar datos.nombre
}

To use objects defined with objeto, declare the corresponding type.

objeto Usuario {
publico:
Usuario(texto nombre) {
ambiente.nombre = nombre
}
texto saludo() {
retornar t"Hola {ambiente.nombre}"
}
}
texto presentar(Usuario usuario) {
retornar usuario.saludo()
}

Version v0.0.2 does not include optional arguments or variable parameter lists. For similar cases, accept a list and process the elements manually.

numero sumar_lista(lista<numero> valores) {
retornar valores.sumar()
}

Apply validations at the start of the function and throw exceptions when requirements are not met.

numero dividir(numero a, numero b) {
si (b == 0) {
lanzar "Cannot divide by zero"
}
retornar a / b
}

Document the meaning of each parameter through comments or self-explanatory names to keep the code readable.