Set of unofficial examples of Julia the high-level, high-performance dynamic programming language for technical computing.
Below are a series of examples of common operations in Julia. They assume you already have Julia installed and working (the examples are currently tested with Julia v1.0.5).
The simplest possible script.
{{ code_file('hello_world.jl') }}
With Julia installed and added to your path
this script can be run by julia hello_world.jl, it can also be run from REPL by typing
include("hello_world.jl"), that will evaluate all valid expressions in that file and return the last output.
The example below shows two simple functions, how to call them and print the results. Further examples of number formatting are shown below.
{{ code_file('functions.jl') }}
Collection of different string examples (string indexing is the same as array indexing: see below).
{{ code_file('strings_basics.jl') }}
{{ code_file('formatting_converting_strings.jl') }}
{{ code_file('string_manipulation.jl') }}
{{ code_file('arrays.jl') }}
{{ code_file('error_handling.jl') }}
Julia has very good multidimensional array capabilities. Check out the manual.
{{ code_file('multiarrays.jl') }}
Julia uses Dicts as
associative collections. Usage is very like python except for the rather odd => definition syntax.
{{ code_file('dicts.jl') }}
For loops can be defined in a number of ways.
{{ code_file('loops_map.jl') }}
if/else statements work much like other languages -
the boolean opperators are true and false.
{{ code_file('booleans.jl') }}
Types are a key way of structuring data within Julia.
{{ code_file('types.jl')}}
The basic syntax for reading and writing files in Julia is quite similar to python.
The simple.dat file used in this example is available
from github.
{{ code_file('io.jl')}}
Packages extend the functionality of Julia's standard library.
{{ code_file('using_packages.jl') }}
Plotting in Julia is only possible with additional Packages. Examples of some of the main packages are given below.
Installed via Pkg.add("Plots"); Pkg.add("GR");
{{ code_file('plots.jl') }}
{{ src_image('plots.svg') }}
The DataFrames.jl package provides tool for working with tabular data.
The iris.csv file used in this example is available
from github.
You may also need CSV.jl package to read data from CSV file.
{{ code_file('dataframes.jl') }}