Variables and Constants
Basic Declaration
Section titled “Basic Declaration”Each variable requires an explicit type followed by the name and, optionally, an initial value.
entero contador = 0texto saludo = "Hola"log activo = verdaderoIf no value is provided, Quetzal assigns a default according to the type (0 for entero, 0.0 for numero, empty string for texto, falso for log).
Mutability
Section titled “Mutability”Variables are immutable by default. Use the var keyword to allow reassignments or methods that mutate the value.
entero var total = 10total += 5
lista<texto> var elementos = ["a", "b"]elementos.agregar("c")Valid Names
Section titled “Valid Names”- Start with a letter or underscore and can contain numbers.
- Support
camelCaseorsnake_case. - Cannot match reserved words like
si,lista,importar,nuevo,ambiente,verdadero,falso,nulo,y,o,no, and others listed in the reference section.
- Variables declared in the main body have global scope within the file.
- Inside functions or objects, scope is limited to the corresponding block.
- Each loop creates its own scope, so variables defined in the header or within the block are not visible outside of it.
entero var acumulado = 0para (entero var numero en [1, 2, 3]) { acumulado += numero}// numero is no longer available hereUsing ambiente
Section titled “Using ambiente”In objects, the reserved word ambiente allows access to internal attributes and methods.
objeto Contador { entero var valor = 0
Contador(entero inicial) { ambiente.valor = inicial }
vacio incrementar() { ambiente.valor++ }}Symbolic Constants
Section titled “Symbolic Constants”Currently there is no specific keyword for global constants. To simulate a constant, declare the variable without var and avoid reassigning it. If you need to share it across multiple files, export it from a dedicated module.
texto MENSAJE_BIENVENIDA = "Bienvenido"exportar { MENSAJE_BIENVENIDA }Best Practices
Section titled “Best Practices”- Prefer descriptive and consistent names.
- Declare variables as close as possible to their use.
- Avoid using mutability unless strictly necessary (e.g., accumulators or changing structures).