Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upOptional namespaces with shared aliases #448
Conversation
bvssvni
added some commits
Mar 5, 2017
bvssvni
merged commit 662d943
into
PistonDevelopers:master
Mar 5, 2017
bvssvni
deleted the
bvssvni:namespace
branch
Mar 5, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
bvssvni commentedMar 5, 2017
•
edited
For design, see #434
This PR adds optional namespaces to Dyon as a way to organize code and avoid name collisions. At the moment this is only supported for loaded modules, not external functions.
How dynamic modules work in Dyon
Dyon uses dynamic modules to organize code. In order for one module to depend on another, you write a loader script, like this:
This puts the functions declared in
graphicsin the prelude of the moduleprogram. You do not have to write any imports, you just call them:This design makes it easy to refactor code, because you can simply copy and paste a function to another module and expect it to work. Since module loading is controlled by the loader script, you can update parts of the program while running.
How optional namespaces work
An optional namespace can be declared at the beginning of the file with the
nskeyword:This puts all functions in this file in an extra namespace
graphics.You can also uses nested namespaces, like this:
To use a namespace, you write
useafter the line withnsand give it an alias:All
usestatements requires an alias. This is designed to make refactoring easier, because you can just change the top of the file instead of going through the whole code.You can also share an alias between multiple imports, like this:
Notice that you still can use the default namespace, so without any name collisions you can just write like this:
Import specific functions while excluding others
When importing specific functions, they will shadow any function in global import:
Rename a specific function