Library is a Quail program that could be accessed from other Quail programs
Any Quail program (*.q)
can be used as a library if it returns a not-null value.
Example:
library.q
:
function add(a, b) return a + b
return {
"add" = add
}
main.q
:
use "library.q" = lib
print(lib.add(3, 7))
Library is loaded with following syntax:
use "library/path/to/file.q" = variableToPlaceLibraryIn
Quail searches for requested libraries in these locations by default:
$cwd$/?
$script$/?
Available wildcards:
Wildcard | Replacement |
---|---|
$cwd$ |
Replaced with ENV user.dir |
$script$ |
Replaced with parent directory of file of main script |
? |
Replaced with the path of requested library |
When you request a library, the following gets executed:
Library cache is being searched for already loaded library with that path.
If found:
If not found:
Quail searches for requested file, using wildcards (9.3.2)
If not found - error raised, algorithm interrupted
Quail ensures that this file is not currently loading from somewhere else in case of circular imports
If circular import is detected - error raised, algorithm interrupted
File is being loaded and executed in new, separate runtime
The return value of the loaded library is placed into cache and returned to provided variable