Parameters
Explicit Types
Section titled “Explicit Types”Each parameter declares its type before the name.
numero sumar(numero a, numero b) { retornar a + b}Modifiable Parameters
Section titled “Modifiable Parameters”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}Lists and JSON as Parameters
Section titled “Lists and JSON as Parameters”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}Object Parameters
Section titled “Object Parameters”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()}Variable Number of Arguments
Section titled “Variable Number of Arguments”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()}Parameter Validation
Section titled “Parameter Validation”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.