Basic Syntax
Quetzal Language uses clean syntax without semicolons. Each instruction occupies its own line or block, and keywords are in Spanish.
Comments
Section titled “Comments”// Single line comment
/* Multi-line comment that can include line breaks.*/
entero valor = 42 // Comment next to codePrimitive Types
Section titled “Primitive Types”| Type | Description | Example |
|---|---|---|
vacio | Absence of value (functions only) | - |
entero | Signed integers | entero edad = 27 |
numero | Floating point values | numero pi = 3.14159 |
texto | Unicode strings | texto saludo = "Hola" |
log | Boolean values | log activo = verdadero |
entero edad = 27numero temperatura = 22.5texto mensaje = "Hola"log activo = verdaderoLists are declared with lista and can be typed or untyped.
// Typed listlista<entero> numeros = [1, 2, 3]lista<texto> nombres = ["Ana", "Luis"]
// Untyped list (can contain any type)lista valores = [1, "dos", verdadero]
// Empty listlista<texto> vacia = []Mutable lists use var and allow methods like agregar, ordenar, or sumar.
lista<texto> var frutas = ["manzana", "naranja"]frutas.agregar("pera")consola.mostrar(frutas.texto())JSON Values (jsn)
Section titled “JSON Values (jsn)”jsn var persona = { nombre: "Ana", edad: 30, activo: verdadero, direcciones: [ { tipo: "casa", ciudad: "Guatemala" }, { tipo: "trabajo", ciudad: "Antigua" } ]}
texto ciudad = persona.direcciones[0].ciudadpersona.establecer("activo", falso)Variables and Mutability
Section titled “Variables and Mutability”Variables are immutable by default. Use the var keyword to allow reassignments or mutating methods.
entero contador = 10 // Immutable (constant)entero var mutable = 5 // Mutable (variable)mutable += 1
lista<entero> var datos = [1, 2]datos.agregar(3)Operators
Section titled “Operators”Arithmetic
Section titled “Arithmetic”entero a = 7entero b = 3
entero suma = a + b // 10entero resta = a - b // 4entero producto = a * b // 21entero cociente = a / b // 2entero residuo = a % b // 1Increment and Decrement
Section titled “Increment and Decrement”entero var valor = 5
valor++ // valor = 6valor-- // valor = 5Comparison
Section titled “Comparison”log igual = a == b // falsolog distinto = a != b // verdaderolog mayor = a > b // verdaderolog menor = a < b // falsolog mayor_igual = a >= b // verdaderolog menor_igual = a <= b // falsoLogical
Section titled “Logical”log condicion1 = verdaderolog condicion2 = falso
// Spanish operatorslog conjuncion = condicion1 y condicion2 // falso (AND)log disyuncion = condicion1 o condicion2 // verdadero (OR)log negacion = no condicion1 // falso (NOT)
// Symbolic operators (equivalent)log and_result = condicion1 && condicion2 // falsolog or_result = condicion1 || condicion2 // verdaderolog not_result = !condicion1 // falsoCompound Assignment
Section titled “Compound Assignment”entero var total = 10
total += 5 // total = 15total -= 3 // total = 12total *= 2 // total = 24total /= 4 // total = 6total %= 4 // total = 2Ternary Operator
Section titled “Ternary Operator”entero edad = 20texto mensaje = edad >= 18 ? "Mayor de edad" : "Menor de edad"Text Interpolation
Section titled “Text Interpolation”Interpolated strings are declared with the t prefix and allow embedding expressions within braces {}.
Basic Syntax
Section titled “Basic Syntax”texto nombre = "Maria"entero edad = 25
// Basic interpolationtexto saludo = t"Hola, {nombre}!"texto info = t"{nombre} tiene {edad} anos"
consola.mostrar(saludo) // "Hola, Maria!"consola.mostrar(info) // "Maria tiene 25 anos"With Expressions
Section titled “With Expressions”You can include any valid expression inside the braces:
entero a = 10entero b = 5
texto operaciones = t"Sum: {a + b}, Difference: {a - b}, Product: {a * b}"// "Sum: 15, Difference: 5, Product: 50"
texto comparacion = t"Is {a} greater than {b}? {a > b}"// "Is 10 greater than 5? verdadero"With Different Types
Section titled “With Different Types”Interpolation automatically converts values to text:
numero precio = 99.99log disponible = verdaderolista numeros = [1, 2, 3]
texto producto = t"Price: ${precio}, Available: {disponible}"texto lista_info = t"Numbers: {numeros}"
jsn datos = { nombre: "Juan", edad: 30 }texto json_info = t"Data: {datos}"Multiline Interpolation
Section titled “Multiline Interpolation”texto nombre = "Juan"entero puntos = 150
texto mensaje = t"Dear {nombre},Your {puntos} points are available.Thank you for using Quetzal!"
consola.mostrar(mensaje)Escaping Braces
Section titled “Escaping Braces”To show literal braces, use double backslash:
entero valor = 42texto con_llaves = t"The value is {valor} and these are braces: \\{literal\\}"// "The value is 42 and these are braces: {literal}"Basic Input and Output
Section titled “Basic Input and Output”The consola methods allow sending messages and requesting data.
Display Messages
Section titled “Display Messages”consola.mostrar("Normal message")consola.mostrar_exito("Successful operation")consola.mostrar_error("An error occurred")consola.mostrar_advertencia("Important warning")consola.mostrar_informacion("Useful information")Request Input
Section titled “Request Input”texto nombre = consola.pedir("Enter your name: ")consola.mostrar_exito(t"Welcome, {nombre}")
// Hidden input (for passwords)texto clave = consola.pedir_secreto("Enter your password: ")Null Value
Section titled “Null Value”The nulo literal represents the absence of value and can be assigned to any type:
entero valor_nulo = nulotexto mensaje_nulo = nulolista<entero> lista_nula = nulojsn json_nulo = nuloWith these elements you can read the rest of the fundamentals and build more complex programs.