<function>
or <operator>
).
This is just notation, and the symbols <
and >
should not be misconstrued as Julia's syntax.
Action | Keyboard Shortcut |
---|---|
Previous Section | Ctrl + 🠘 |
Next Section | Ctrl + 🠚 |
List of Sections | Ctrl + z |
List of Subsections | Ctrl + x |
Close Any Popped Up Window (like this one) | Esc |
Open All Codes and Outputs in a Post | Alt + 🠙 |
Close All Codes and Outputs in a Post | Alt + 🠛 |
Unit | Acronym | Measure in Seconds |
---|---|---|
Seconds | s | 1 |
Milliseconds | ms | 10-3 |
Microseconds | μs | 10-6 |
Nanoseconds | ns | 10-9 |
In the following, we present the very basics for getting started with Julia. As we haven't introduced functions or macros yet, we'll keep the discussion to a bare minimum. Specifically, this means we'll limit ourselves to covering interactive and non-interactive modes, along with approaches for adding comments and specifying paths.
The REPL, short for "Read-Eval-Print Loop," refers to Julia's working environment. This activates when you run julia.exe
, allowing you to enter inputs at the prompt julia>
and receive their corresponding outputs. This usage of Julia is known as interactive mode.
Throughout this website, we'll assume you're working with a code editor, rather than directly interacting with the REPL. In particular, we'll be using VS Code as our code editor of choice. To get started with Julia in VS Code, you'll need to install the Julia extension. You can find this by navigating to the Extensions tab, as indicated below with a blue circle.
The REPL is situated at the bottom of the screen, while the code must be written in the editor area above the REPL. Note that when starting a new file in VS Code, you'll need to specify the programming language you want to use. You can do this by clicking on the language option located at the bottom corner of the screen, or by using the keyboard shortcut Ctrl+k + M and typing "julia".
Julia allows you to include comments in your code, just like in any programming language. Comments are lines of text that won't be executed but are useful for clarifications and explanations.
To add a single-line comments, simply precede the text with the #
symbol. The #
symbol can be placed anywhere on a line, and anything written after it will be ignored. Alternatively, you can add a multi-line comment by beginning the text with #=
and end it with =#
.
# This is an example of a comment
x = 2 # `x=2` is run, but anything after `#` won't
#= This is an example of a longer comment.
It can be split into several lines, and
can have any length. =#
File management systems vary across operating systems, making the syntax for specifying file paths in Julia differ depending on them. Below, we provide examples that illustrate the syntax for a folder C:\user\julia
on Windows and /user/julia
on Linux/macOS. Alternatively, the function joinpath
provides a platform-agnostic approach to specifying file paths, making your code portable across systems.
File management systems vary across operating systems, which affects the syntax for specifying file paths in Julia. In this respect, Julia provides two approaches. The first one involves using operating system-specific syntax, as illustrated by the examples below for a file C:\user\file.jl
on Windows and /user/file.jl
on Linux/macOS. A more versatile alternative is the joinpath
function, which applies regardless of the operating system.
# On Windows (note that double \\)
"C:\\user\\file.jl"
# On Unix-based systems (e.g., macOS or Linux)
"/user/file.jl"
# on any operating system
joinpath("/", "user", "file.jl")
Two special paths have a convenient shortcut:
@__DIR__
, which identifies the directory where your script is saved.
For instance, if your script is in C:\user\julia
, then joinpath(@__DIR__, "graphs")
refers to C:/user/julia/graphs
.
homedir()
, which indicates the user's home directory.
This refers to C:\Users\username
on Windows (where "username" is your actual user), and is the equivalent of ~
on Linux. For instance, you can access Google Drive's folder located on either C:\Users\martin\GoogleDrive
or \home\martin\GoogleDrive
by the command joinpath(homedir(), "GoogleDrive")
.
You can also work non-interactively with Julia. This requires storing a script in a file to eventually execute it. For instance, the following line executes a file at C:\user\julia\graphs.jl
on Windows or /users/julia/graphs.jl
on macOS/Linux systems:
include(joinpath("/", "user", "julia", "graphs.jl"))