THIS IS UNFINISHED – I don’t know how complete this is, but it’s abandoned until I actually use packages in the future.
- As of 7.1.0, 2013-11-28, I stopped attempting to use packages because I have such tightly-interwoven dependencies that I cannot separate my functions out into separate files. It’s terrible, but I have to use one large file with everything inside. De-tangling it will be completely impossible, because of the test case concept I wrote.
-
The last time I was interested in this topic was around Mythryl 6.0.0
Whatever is here is all there is. If and when I actually do get to use packages at length, then I can write some information on it.
Notes ∞
FIXME – I need to understand the difference between an API and a package.
TODO:
- https://mythryl.org/my-Multi-file_Projects__Libraries_and_API_Definitions.html
-
https://mythryl.org/my-Multi-file_Projects__Compiling_a_Stand-Alone_Executable.html
I’d need to go over APIs first? (yes, it defines the type restriction stuff)
Reasoning ∞
Reducing complexity
When a program becomes one very large file, it gets very difficult to read through.
Moving functions into another file keeps them accessible but gets them out of the way.
Organization
Packages let you group similar functions together.
Reducing pollution
Not all parts of your program will need access to all of your functions all of the time.
Once functions are moved into various packages you can be selective about what parts of your program have access to what functions.
Packages ∞
TODO – Indent with four spaces. I don’t know why, it’s just a convention. Maybe it’s so that it’s the same as function indentation?
package example_package { fun double( i ) = { 2 * i; }; }; printf "%d\n" ( example_package::double( 2 ) ); # => # 4
package aliases ∞
An alias lets you use a shorter or otherwise more clear name.
package example_package { fun double( i ) = { 2 * i; }; }; package p = example_package; printf "%d\n" ( p::double( 3 ) ); # => # 6
include ∞
When a package is included in the current namespace, every function from that package is available without using the package name.
package example_package { fun double( i ) = { 2 * i; }; }; include example_package; printf "%d\n" ( double( 4 ) ); # => # 8
Nesting packages ∞
Here we have two packages. Package two is within package one.
package one { fun double( i ) = { 2 * i; }; package two { fun triple( i ) = { 3 * i; }; }; }; printf "%d\n" ( one::double( 1 ) ); printf "%d\n" ( one::two::triple( 1 ) ); # => # 2 # 3
