Skip to content

Import and Export

Quetzal uses importar and exportar to share code between files.

Use the exportar block at the end of a file to make symbols available to other files.

utilidades.qz
entero sumar(entero a, entero b) {
retornar a + b
}
objeto Calculadora {
libre numero multiplicar(numero a, numero b) {
retornar a * b
}
}
texto VERSION = "1.0.0"
exportar {
sumar,
Calculadora,
VERSION
}

Use importar with desde to bring symbols from another file.

principal.qz
importar {
sumar,
Calculadora,
VERSION
} desde "utilidades.qz"
entero resultado = sumar(5, 3)
numero producto = Calculadora.multiplicar(4.5, 2.0)
consola.mostrar("Version: " + VERSION)

Use como to rename imported symbols.

importar {
sumar como suma_enteros,
Calculadora como Calc,
VERSION como version_actual
} desde "utilidades.qz"
entero resultado = suma_enteros(10, 20)

Quetzal provides built-in modules with the quetzal/ prefix.

importar { Matematica } desde "quetzal/matematica"
numero pi = Matematica.PI
numero resultado = Matematica.sumar(2, 3)
numero seno = Matematica.seno(Matematica.PI / 2)
ModuleDescription
quetzal/matematicaMathematical functions and constants
quetzal/archivoFile system operations
quetzal/sistemaSystem utilities

Paths are relative to the main file that invokes the interpreter.

importar { Usuario } desde "./modulos/usuarios.qz"
importar { validar } desde "../compartido/validaciones.qz"
  • Export only what other modules need
  • Use descriptive names for exported symbols
  • Group related functionality in the same module
  • Document exported symbols with comments