Skip to content

Instantly share code, notes, and snippets.

@tk3369
Last active June 22, 2021 20:59
Show Gist options
  • Save tk3369/e88059bb0b1078be5d2516e43c60b2cd to your computer and use it in GitHub Desktop.
Save tk3369/e88059bb0b1078be5d2516e43c60b2cd to your computer and use it in GitHub Desktop.
Getting started with Julia

Setup

  • Visit Julia home page to download pre-built binaries and access documentation
  • Install VSCode, and install Julia Language extension
  • For an interactive environment, try Pluto

Essential packages

Install these packages in your root environment:

Workflow: scripting

Create a new directory and change to that directory.

mkdir project1
cd project1

Start Julia REPL with the following command:

julia --project=.

Install any packages that you want to use. First press ] to go into Pkg mode, then:

add CSV
add DataFrames
etc.

Use a text editor, create an empty script (e.g. script.jl) and save into this directory.

Enable Revise and monitor the script.

using Revise
includet("script.jl")

From this point on, you can start writing functions in the script file. When you are ready to test, save the file and switch over to the REPL to call that function.

For example, let's say the script has:

function hello()
    println("world")
end

You just go to the REPL and call it:

hello()

workflow: julia package

Start Julia REPL and generate a new package as follows:

] generate MyPackgae

It shoud create a new MyPackage directory. Exit REPL and change to that directory.

cd MyPackage

Restart Julia REPL with the following command:

julia --project=.

Install any packages that you want to use. First press ] to go into Pkg mode, then:

add CSV
add DataFrames
etc.

Import Revise and your package:

using Revise, MyPackage

From this point on, you can update any source code in the package directory. When you're ready for testing, switch back to the REPL and call any function:

MyPackage.hello()

You don't need to prefix with MyPackage for exported functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment