Packages will also be covered in much more depth and variety in the intermediate MUF programming chapter, but they are such a great organizational help that I can't resist covering the bare basics of them here.
Everyone has a variety of different interests, and we all learn to compartmentalize them somewhat just to keep our sanity: We keep the cooking stuff in the kitchen, the woodworking stuff in the workshop, the financial records in the study, and so forth.
Anyone really using a Muq system for long will quickly discover that sanity demands that the functions and data created for one project be kept separate from those for other projects.
Muq provides "packages" for this purpose. At any given
time, you are working in one particular package, and all
functions and global variables that you create are put in
this package. To see what package you are in, you can print
out the value of
@$s.package. To see the functions in
the current package do
lf (List Functions); to see
the variables and their values, do
However, since it is very important to keep in mind what package one is in at any given instant, and since some of us (me!) are quite absent-minded, MUF reminds us constantly which package we are in by printing out the package name to the left of each stack listing.
You change the package you are "in" using the
inPackage function. If you try to
change to a package which doesn't exist, it
is automatically created for you:
Stack: "kitchen" inPackage kitchen: 2 --> story kitchen: "workshop" inPackage workshop: 1 --> story workshop: story workshop: 1 pop "kitchen" inPackage kitchen: story kitchen: 2
Notice that we now have two different variables named "story", one in the "kitchen" package and one in the "workshop" package, holding different values without conflicting. (We could also create different functions with the same name in the two packages, without conflicting.)
It can sometimes be useful to refer to a value or function in one package when you are in another package:
kitchen: story kitchen: 2 pop workshop::story kitchen: 1
Just prefix the symbol name you want by the package name, and separate them by a double colon.
If cleanliness is next to godliness, packages just might be your road to heaven grin.
Go to the first, previous, next, last section, table of contents.