Operators
Arithmetic
Section titled “Arithmetic”| Operator | Description | Example |
|---|---|---|
+ | Adds two numeric values or concatenates text. | numero total = a + b |
- | Subtracts the second operand from the first. | entero diferencia = a - b |
* | Multiplication. | entero producto = a * b |
/ | Division. For integers, division is integer division. | entero cociente = a / b |
% | Remainder or modulo. | entero residuo = a % b |
entero suma = 5 + 3texto combinado = "Hola" + " Quetzal"Relational
Section titled “Relational”| Operator | Description |
|---|---|
== | Equality. |
!= | Inequality. |
> | Greater than. |
< | Less than. |
>= | Greater than or equal. |
<= | Less than or equal. |
log es_mayor = 10 > 5log es_igual = "texto" == "texto"Logical
Section titled “Logical”Quetzal supports both symbolic operators (&&, ||, !) and their Spanish equivalents (y, o, no).
log acceso = (usuario.autenticado y !usuario.bloqueado)log disponible = (stock > 0) o (pedido_en_camino == verdadero)log negado = no accesoNon-boolean values are automatically converted to log following interpreter rules (e.g., empty lists are falso).
Assignment
Section titled “Assignment”| Operator | Description |
|---|---|
= | Simple assignment. |
+= | Add and assign. |
-= | Subtract and assign. |
*= | Multiply and assign. |
/= | Divide and assign. |
%= | Calculate remainder and assign. |
entero var acumulado = 0acumulado += 5acumulado -= 2Increment and Decrement
Section titled “Increment and Decrement”The ++ and -- operators are available in postfix form.
entero var contador = 0contador++contador--Ternary Operator
Section titled “Ternary Operator”The form condition ? value_if_true : value_if_false is available for quick evaluations.
entero numero = -10entero absoluto = numero < 0 ? -numero : numeroOperators for Lists and JSON
Section titled “Operators for Lists and JSON”Lists and jsn values provide methods instead of specific operators. For example, lista.concatenar(otra_lista) or json.fusionar(otro_json). See the data types sections for more information.
Precedence
Section titled “Precedence”- Function calls and member access.
- Unary operators (
no,!,++,--). - Multiplication and division.
- Addition and subtraction.
- Comparisons.
- Logical operators (
y,o). - Assignments (
=,+=, etc.).
Use parentheses to clarify intent when combining multiple operators.
Complete Examples
Section titled “Complete Examples”// Arithmetic operatorsentero suma(entero a, entero b) { retornar a + b}
entero resta(entero a, entero b) { retornar a - b}
// Logical operatorslog es_verdadero(log valor) { retornar valor}
log es_falso(log valor) { retornar !valor}
// Comparison operatorslog es_igual(entero a, entero b) { retornar a == b}
log es_diferente(entero a, entero b) { retornar a != b}
log es_mayor(entero a, entero b) { retornar a > b}
log es_menor(entero a, entero b) { retornar a < b}
// Compound operatorsentero suma_compuesta(entero var valor, entero incremento) { valor += incremento retornar valor}
// Run functions to test operatorsentero resultado_suma = suma(5, 10)entero resultado_resta = resta(10, 5)log resultado_es_igual = es_igual(5, 5)entero resultado_suma_compuesta = suma_compuesta(5, 10)