Book Image

Julia 1.0 Programming Complete Reference Guide

By : Ivo Balbaert, Adrian Salceanu
Book Image

Julia 1.0 Programming Complete Reference Guide

By: Ivo Balbaert, Adrian Salceanu

Overview of this book

Julia offers the high productivity and ease of use of Python and R with the lightning-fast speed of C++. There’s never been a better time to learn this language, thanks to its large-scale adoption across a wide range of domains, including fintech, biotech and artificial intelligence (AI). You will begin by learning how to set up a running Julia platform, before exploring its various built-in types. This Learning Path walks you through two important collection types: arrays and matrices. You’ll be taken through how type conversions and promotions work, and in further chapters you'll study how Julia interacts with operating systems and other languages. You’ll also learn about the use of macros, what makes Julia suitable for numerical and scientific computing, and how to run external programs. Once you have grasped the basics, this Learning Path goes on to how to analyze the Iris dataset using DataFrames. While building a web scraper and a web app, you’ll explore the use of functions, methods, and multiple dispatches. In the final chapters, you'll delve into machine learning, where you'll build a book recommender system. By the end of this Learning Path, you’ll be well versed with Julia and have the skills you need to leverage its high speed and efficiency for your applications. This Learning Path includes content from the following Packt products: • Julia 1.0 Programming - Second Edition by Ivo Balbaert • Julia Programming Projects by Adrian Salceanu
Table of Contents (18 chapters)

Packages

Most of the standard library in Julia (which can be found in /share/julia/base and /share/julia/stdlib, relative to where Julia was installed) is written in Julia itself. The rest of Julia's code ecosystem is contained in packages that are simply GitHub repositories. They are most often authored by external contributors, and already provide functionality for such diverse disciplines such as bioinformatics, chemistry, cosmology, finance, linguistics, machine learning, mathematics, statistics, and high-performance computing. A package listing can be found at http://pkg.julialang.org.

Julia's installation contains a built-in package manager, Pkg, for installing additional packages that are written in Julia. Version and dependency management is handled automatically by Pkg.

Pkg has a REPL mode, which can be started from within the Julia REPL by entering the ] key, which is often called the REPL's package mode. The Pkg mode is shown as a blue prompt, like this: (v1.0) pkg>.

From this mode, we can start all functions of Pkg. To return to the normal REPL mode, press Backspace or Ctrl C.

To initialize your environment, enter the init command, which creates an empty Project.toml file in your Julia installation folder.

Adding a new package

Before adding a new package, it is always a good idea to update your package database for the already installed packages with the up command. Then, add a new package by issuing the add PackageName command, and execute it by using PackageName in the code or in the REPL.

For example, to add 2D plotting capabilities, install the Plots package with add Plots in the Package mode by first typing ]. This installs the Plots package and all of its dependencies, building them when needed.

To make a graph of 100 random numbers between 0 and 1, execute the following commands:

using Plots 
plot(rand(100))

The rand(100) function is an array with 100 random numbers. This produces the following output:

A plot of white noise with Plots

After installing a new Julia version, update all the installed packages by running up in the Pkg REPL-mode.