Import and Export
Quetzal uses importar and exportar to share code between files.
Exporting
Section titled “Exporting”Use the exportar block at the end of a file to make symbols available to other files.
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}Importing
Section titled “Importing”Use importar with desde to bring symbols from another file.
importar { sumar, Calculadora, VERSION} desde "utilidades.qz"
entero resultado = sumar(5, 3)numero producto = Calculadora.multiplicar(4.5, 2.0)consola.mostrar("Version: " + VERSION)Import with Alias
Section titled “Import with Alias”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)Native Modules
Section titled “Native Modules”Quetzal provides built-in modules with the quetzal/ prefix.
importar { Matematica } desde "quetzal/matematica"
numero pi = Matematica.PInumero resultado = Matematica.sumar(2, 3)numero seno = Matematica.seno(Matematica.PI / 2)Available Native Modules
Section titled “Available Native Modules”| Module | Description |
|---|---|
quetzal/matematica | Mathematical functions and constants |
quetzal/archivo | File system operations |
quetzal/sistema | System utilities |
Relative Paths
Section titled “Relative Paths”Paths are relative to the main file that invokes the interpreter.
importar { Usuario } desde "./modulos/usuarios.qz"importar { validar } desde "../compartido/validaciones.qz"Best Practices
Section titled “Best Practices”- Export only what other modules need
- Use descriptive names for exported symbols
- Group related functionality in the same module
- Document exported symbols with comments