Introduction

While the things we have gone over in the past Julia tutorials; functions, constructors, and types are certainly valuable, there is no possible way that one programmer could build an entire ecosystem from scratch. That being said, programmers often use packages to perform arithmetic that their package is not necessarily targeted towards, but requires. Packages are repositories of code that can be re-used as dependencies for other packages to iterate and build on.

We have already taken a broad overview of Pkg and how it can be used to install packages for the Julia programming language. Today we are going to be working with a module called Compose.jl to get some practice with programming in Julia. I chose this library because it is a functional and declarative library that follows the same programming methodologies and principles we have been covering in these tutorials.

Packages — The Basics

In order to add a package in Julia, we will use Pkg. You can do this by either importing Pkg into Julia with using, or just using the Pkg REPL that can be accessed by pressing ] in the Julia REPL. Adding is relatively straight forward and can be done using either the Pkg.add() method or the add command in the Pkg REPL. Of course, today we are going to be working with Compose.jl, so you might want to go ahead and add it:

julia> ]
pkg> add Compose

This will add Compose to our global package environment. Some Julia developers would strongly advise against this, but I am one to disagree — I think that having dependencies on your machine is perfectly alright so long as they are frequently used dependencies. Furthermore, one can always remove their packages with the rm command.

julia> ]
pkg> rm Compose

In order to get a module into our Julia runtime environment, we have a series of different options to import it. First and foremost is using. Using just means that the package is going to be pre-compiled and called from within the run-time and not be mutable from within the runtime. We can use the Compose package with

using Compose

#programming #julia #julialang #data-science #coding

How To Use Modules In Julia
2.45 GEEK