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)

Startup options and Julia scripts

Without any options, the julia command starts up the REPL environment. A useful option to check your environment is julia -v. This shows Julia's version, for example, julia version 1.0.0. (The versioninfo()function in REPL is more detailed, and the VERSION constant only gives you the version number: v"1.0.0"). An option that lets you evaluate expressions on the command line itself is -e, for example:

julia -e 'a = 6 * 7;
println(a)'

The preceding commands print out 42 (this also works in a PowerShell window on Windows, but in an ordinary Windows Command Prompt, use " instead of the ' character).

Some other options that are useful for parallel processing will be discussed in Chapter 9, Running External Programs. Type julia -h for a list of all options.

A script.jl file with Julia source code can be started from the command line with the following command:

julia script.jl arg1 arg2 arg3

Here, arg1, arg2, and arg3 are optional arguments to be used in the script's code. They are available from the global constant ARGS. Take a look at the args.jl file, which contains the following:

for arg in ARGS 
    println(arg) 
end 

The julia args.jl 1 Red C command prints out 1, Red, and C on consecutive lines.

A script file can also execute other source files by including them in the REPL; for example, main.jl contains include("hello.jl"), which will execute the code from hello.jl when called with julia main.jl.

Sometimes, it can be useful to know when code is executed interactively in the REPL, or when started up with the Julia VM with the julia command. This can be tested with the isinteractive() function. The isinteractive.jl script contains the following code:

println("Is this interactive? $(isinteractive())")

If you start this up in the REPL with include("isinteractive.jl"), the output will be Is this interactive? true.

When started up in a Terminal window as julia isinteractive.jl, the output is Is this interactive? false.

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit https://github.com/TrainingByPackt/Julia-1-Programming-Complete-Reference-Guide.