\( \newcommand\D{\mathrm{d}} \newcommand\E{\mathrm{e}} \newcommand\I{\mathrm{i}} \newcommand\bigOh{\mathcal{O}} \newcommand{\cat}[1]{\mathbf{#1}} \newcommand\curl{\vec{\nabla}\times} \newcommand{\CC}{\mathbb{C}} \newcommand{\NN}{\mathbb{N}} \newcommand{\QQ}{\mathbb{Q}} \newcommand{\RR}{\mathbb{R}} \newcommand{\ZZ}{\mathbb{Z}} \)
UP | HOME

Julia

Table of Contents

1. Getting Started with Emacs

Download Julia and put it somewhere. You don't install a compiler or interpreter the same way you do for, say, Python. It's executed locally.

~$ mkdir -p src/julia/
~$ cd src/julia/
~/src/julia/$ wget https://julialang-s3.julialang.org/bin/linux/x64/1.10/julia-1.10.1-linux-x86_64.tar.gz
~/src/julia/$ tar zxvf julia-1.10.1-linux-x86_64.tar.gz 

Then you append to your ~/.bashrc file:

# Julia
export PATH="$PATH:/home/alex/src/julia/julia-1.10.1/bin"

Source your bashrc again, and you should be able to start working with Julia.

I couldn't ever get Julia's LSP working with Emacs, so I decided to work with Julia-snail. On Debian systems, it helps to install libvterm-dev on the command line, then add to your init file:

(use-package vterm
  :ensure t)

(use-package julia-mode
  :ensure t)

(use-package julia-snail
  :ensure t
  :hook (julia-mode . julia-snail-mode))

;; I hate this, but julia-snail just couldn't find the binary!
(setq julia-snail-executable "/home/alex/src/julia/julia-1.10.1/bin/julia")

To run a REPL, you can just use C-c C-z in Emacs.

2. Starting a project

To start a new project, run Julia in the parent directory for the project, the run the code:

] 
pkg > generate MyProject

This will create the following files and subdirectories:

MyProject/
├── Project.toml
└── src
    └── MyProject.jl

It's good practice to create a subdirectory for unit tests (and it's insane to program without unit testing your code), as well as a directory for your documentation. We can do it in Julia by switching to "shell mode" (typing in ;) then we can mkdir:

;
shell> mkdir -p MyProject/{docs,test}
shell> cd MyProject

Switch back to Julia and activate the project:

shell> cd MyProject
]
pkg > activate .
(MyProject) pkg >

Now we can start working on our project.

3. Docstrings

Docstrings are well-documented and should be used whenever possible.

There are also "admonitions" which look like !!! admonition or !!! admonition "Name". The available admonitions are: danger, warning, info/note, tip. They start a 4-spaced indented section of documentation which elaborates on various aspects of the thing being documented.

4. Interesting Stuff

Last Updated 2024-03-21 Thu 10:37.