Skip to content
This repository was archived by the owner on Oct 26, 2022. It is now read-only.

Latest commit

 

History

History
128 lines (72 loc) · 3.53 KB

File metadata and controls

128 lines (72 loc) · 3.53 KB

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).

Build Status

Hello World

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.

Simple Functions

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') }}

Strings Basics

Collection of different string examples (string indexing is the same as array indexing: see below).

{{ code_file('strings_basics.jl') }}

String: Converting and formatting

{{ code_file('formatting_converting_strings.jl') }}

String Manipulations

{{ code_file('string_manipulation.jl') }}

Arrays

{{ code_file('arrays.jl') }}

Error Handling

{{ code_file('error_handling.jl') }}

Multidimensional Arrays

Julia has very good multidimensional array capabilities. Check out the manual.

{{ code_file('multiarrays.jl') }}

Dictionaries

Julia uses Dicts as associative collections. Usage is very like python except for the rather odd => definition syntax.

{{ code_file('dicts.jl') }}

Loops and Map

For loops can be defined in a number of ways.

{{ code_file('loops_map.jl') }}

Conditional Evaluation

if/else statements work much like other languages - the boolean opperators are true and false.

{{ code_file('booleans.jl') }}

Types

Types are a key way of structuring data within Julia.

{{ code_file('types.jl')}}

Input & Output

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 and Including of Files

Packages extend the functionality of Julia's standard library.

{{ code_file('using_packages.jl') }}

Plotting

Plotting in Julia is only possible with additional Packages. Examples of some of the main packages are given below.

Plots

Plots.jl Package Page

Installed via Pkg.add("Plots"); Pkg.add("GR");

{{ code_file('plots.jl') }}

{{ src_image('plots.svg') }}

DataFrames

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') }}