# Introducing Julia/Modules and packages
## Modules and packages

Julia code is organized into files, modules, and packages. Files containing Julia code use the .jl file extension.

### Modules

Related functions and other definitions can be grouped together and stored in modules. The structure of a module is like this:
and in between these lines you can put functions, type definitions, constants, and so on.
One or more modules can be stored in a package, and these are managed using the git version control system. Most Julia packages, including the official ones, are stored on GitHub, where each Julia package is, by convention, named with a ".jl" suffix.

#### Installing modules

To use an official (registered) Julia module on your own machine, you download and install the package containing the module from the main GitHub site. A list of all officially registered packages can be found in the Julia General Registry on GitHub, but it's easier to search for packages using the JuliaHub and Julia Packages sites.
To download and install a package, you can use Julia's package manager, Pkg. Start by typing a right bracket ] into the REPL to enter the package manager, then use the add command. You don't have to use quotes or the ".jl" suffix.
(If you are not directly connected to the internet, you need to give the name of a proxy before calling the package installer.)
The (v1.0) in the prompt tells you that you're working in the default project, "v1.0", in ~/.julia/environments/. There's a new default project for every release, so you'll probably see v1.7 or v1.8 as the default project during 2022. (A project is a typical - and the most common - way to define a Julia environment, which is a set of packages that together define the way Julia code loads and runs.)
If you want to update the packages you have, use the up command:
For more information about Julia's powerful package management system, refer to the extensive documentation.
To leave the package manager mode, press the Backspace/Delete key.

#### Using modules/packages

After installation, to start using functions and definitions from the package, you tell Julia to make the code available to your current session, with the using or import statements, which accept the names of one or more installed modules:
On success, all the definitions in the Calculus package are available for use. If the definitions inside the Calculus modules were exported by the author(s), you can use them without the module name as prefix (because we used using):
If the author(s) don't export the definitions, or if we use import rather than using, you can still access them, but you have to type the module name as a prefix:
but that's unnecessary in this particular example, as we've seen.
So when you write your own modules, the functions that you choose to export can be used without the module name as prefix. Those that you don't export can still be used, but only if they are prefixed with the module name. For example, in the module called MyCoolModule, the mycoolfunction was exported. So the prefix is optional:
Inside the module, this function was exported, using the export statement:

#### using and import

import is similar to using, but differs in a few ways, for example, in how you access the functions inside the module. Here's a module with two functions, one of which is exported:
Use import to import the module:
Notice that mycoolfunction could be accessed only when you use the module prefix. This is because the MyModule module was loaded using import rather than using. Similarly for mysecretfunction:
You can specify a set of modules:
Another important difference is when you want to modify or extend a function from another module. You can't use using, you have to import the specific function.

#### Include

If you want to use code from other files that aren't contained in modules, use the include function. This evaluates the contents of the file in the context of the current module, searching relative to the path of the source file from which it is called. It's like you just pasted the code in. This is useful for building code from a number of smaller files.

### How does Julia find a module?

Julia looks for module files in directories defined in the LOAD_PATH variable.
To make it look in other places, add some more using push!:
And, since you don't want to do this every single time you run Julia, put this line into your startup file ~/.julia/config/startup.jl, which runs each time you start an interactive Julia session.
Julia looks for files in those directories in the form of a package with the structure:
Or, if not in Package form (see below), it will look for a filename that matches the name of your module:
and this would look in the LOAD_PATH for a file called MyModule.jl and load the module contained in that file.

### Packages

To see all the packages you've installed in your current project:

#### Structure of a package

Julia uses git for organizing and controlling packages. By convention, all packages are stored in git repositories, with a ".jl" suffix. So the Calculus package is stored in a Git repository called Calculus.jl. This is how the Calculus package is organized in terms of files on disk:

## Standard libraries

The Base and Core modules are always available in Julia. There is a set of standard (or stdlib) modules that are installed with Julia but are not all loaded at the start of a Julia session.
If a stdlib module is not already loaded, load them in the usual way, with using or import.
Julia version 1.7 includes the following packages:
| Base64 | encode and decode Base64 strings |
| CRC32c | calculate CRC-32c checksums |
| Dates | work with Dates and Times |
| DelimitedFiles | readdlm and writedlm functions to read and write delimited text data |
| Distributed | working with multiple machines on clusters |
| Downloads | downloading files |
| FileWatching | watching files and directories for changes |
| Future | implements future behavior of already existing functions which will replace the current version in a future release |
| InteractiveUtils | help and introspection functions (usually loaded with the REPL) |
| Libdl | dynamic linker |
| LibGit2 | bindings to the Git library |
| LinearAlgebra | linear algebra functions |
| Logging | recording the history and progress of computations |
| Markdown | support for Markdown text formatting conventions |
| Mmap | working with memory-mapped arrays |
| Pkg | managing the installation of packages |
| Printf | C-style printf formatting |
| Profile | tools for profiling performance |
| Random | random number generation |
| REPL | Julia's interactive command-line REPL |
| Serialization | writing and reading Julia data |
| SHA | provides support for Secure Hash Algorithms (SHA) |
| SharedArrays | shared arrays |
| Sockets | TCP socket support |
| SparseArrays | arrays that save space compared with dense arrays |
| Statistics | basic statistics functions: std, cor, var, cov, mean, median, quantile, |
| SuiteSparse | |
| TOML | parsing TOML files |
| Test | testing tools |
| Unicode | some Unicode utilities |
| UUIDs | generating universally unique identifiers |