Sõnastik

Valige vasakul üks märksõnadest ...

Programming in JuliaPackages

Lugemise aeg: ~10 min

A package is a collection of Julia files that provide functionality beyond the core functionality available in every Julia program. Packages achieve separation of concerns at the community level: someone else solves a problem of general interest, and then you can leverage their work and focus on applying it to the problem at hand.

Julia has a built-in package management system. Package management is important because dependencies and versions can quickly become a mess if you are trying to copy code files from other people and put them alongside the files in your project. The package manager is alert to these dependencies and does the computational work to resolve them. It also stores the package code in a central location on your computer so that it is visible to Julia regardless of where your scripts are located.

To add a Julia package, do using Pkg; Pkg.add("PackageName") from a Julia session. Then using PackageName to load the package. Important packages include

  • Plots There are many plotting packages in Julia, but this is the closest the ecosystem has to a standard.
  • DataFrames The standard package for storing tabular data.
  • CSV Reading data stored in comma-separated value files.
  • PyCall Interfacing with Python.

Packages might use lots of variable names internally, and some of them might conflict with names you're using. For this reason, package code is wrapped in a module, which is a separate variable workspace.

You can load a module by running, for example, import Plots or using Plots. With the import keyword, your name space and that of the module are kept separate, and you have to access variables within the module using dot syntax: Plots.histogram. In the latter case, any names exported by the module become available in the importing namespace (without the dot syntax). You can also choose specific functions to import: using Plots: histogram

Exercises

Exercise
To import just the DataFrame function from DataFrames, we would use what statement?

Solution. using DataFrames: DataFrame

Exercise
If we want to be able to solve equations using SymPy.solve, what import statement should we run first?

Solution import SymPy

Bruno
Bruno Bruno