Introduction to the Julia programming language

Installation

You can download the installer at https://julialang.org/

On Windows you have to set the path manually, e.g. C:\Julia-1.3.1\bin

Let’s fire up a command line and type: julia

You will be greeted with a nice little ascii art and the prompt.

If You want to close the prompt You can use CTRL + D

Hello Julia

To get over with, here is the hello world

julia> show("Hello Julia")
"Hello Julia"

Julia has a show function which gives you decorated text interpretations

But there is also a print function

julia> print("Hello Julia")
Hello Julia

 

Writing Programs

julia code is put into files with the file extension .jl

so let’s write the hello julia to a file

We can start it via

julia hello-julia.jl

Reading and Writing Files

open("data.txt") do file
    for line in eachline(file)
        println(line)
    end
end

asdf

open("data.txt") do file
    for line in enumerate(eachline(file))
        println(line[1], ": ", line[2])
    end
end

Reading CSV

As a developer with interest in data science I want to know what packages exist to handle data. The first one is the csv package to deal with comma separated values.

julia> import Pkg; Pkg.add("CSV")
julia>using CSV
julia>csv = CSV.read("./my_cars.csv")

5×4 DataFrames.DataFrame
│ Row │ Make   │  Model  │  Bought │  Sold │
│     │ String │ String  │ Int64   │ Int64 │
├─────┼────────┼─────────┼─────────┼───────┤
│ 1   │ Fiat   │  Punto  │ 2005    │ 2009  │
│ 2   │ Ford   │  Escort │ 2009    │ 2010  │
│ 3   │ Ford   │  Fusion │ 2003    │ 2012  │
│ 4   │ Audi   │  A5     │ 2012    │ 2099  │
│ 5   │ Honda  │  Jazz   │ 2015    │ 2099  │

Plots

import Pkg; Pkg.add("Plots")
using Plots
x = 1:10; 
y = rand(10); 
plot(x, y)