You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently all functions in Dyon live in the same namespace. This is because we try to use dynamic modules as a way of organizing code, with the ability to control and swap dependencies. However, it leads to problems when you try to reuse code across projects, because two external functions from two different projects can collide.
This is an idea for adding support for namespaces, but keeping dynamic modules as the way code is organized.
Call parent module functions
Instead of loading source from files, the namespaces are functions in the parent module that gets called upon loading:
// Calls `fn input() -> res[any]` in parent module when loading.// Imports `press_args` and `release_args` into the prelude for this module.// An error is reported if the loading fails.use input::{press_args, release_args}fnmain(){
...// Function is imported into prelude.a:= press_args()
...
}
This is equivalent to the following loader script:
fnmain(){// Load `input` module using external function `input`.
input := unwrap(input())// Load the main program using `input` as import.
main := unwrap(load(source:"src/main.dyon", imports:[input]))// Run program.
call(main,"main",[])}
With imports the loader script can be reduced to:
fnmain(){
main := unwrap(load("src/main.dyon"))
call(main,"main",[])}
When not using a loader script, the function that returns the module can be an external function.
Related to #388.
Currently all functions in Dyon live in the same namespace. This is because we try to use dynamic modules as a way of organizing code, with the ability to control and swap dependencies. However, it leads to problems when you try to reuse code across projects, because two external functions from two different projects can collide.
This is an idea for adding support for namespaces, but keeping dynamic modules as the way code is organized.
Call parent module functions
Instead of loading source from files, the namespaces are functions in the parent module that gets called upon loading:
This is equivalent to the following loader script:
With imports the loader script can be reduced to:
When not using a loader script, the function that returns the module can be an external function.
Global imports
Global imports can be supported:
Renaming
One can also rename imports:
Loading from source
In the loader script, one can define a module that is loaded from source:
One can also use current objects to reuse a loaded module:
The text was updated successfully, but these errors were encountered: