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
- Parallel Computing and Scientific Machine Learning (SciML): Methods and Applications — SciML is a fun project
- JuliaFormatter to enforce a style guide
- Design by contract seems difficult in Julia, but there are at least
two libraries worth examining further:
- DesignByContract.jl allows design-by-contract
- Spec.jl similarly allows for annotating functions with
@pre
and@post
conditions
- Adding static type checking to Julia in 100 lines of code
- Mutability in Julia is not as intuitive as it should be…
- Jeff Bezanson, Stefan Karpinski, Viral B. Shah, Alan Edelman,
"Julia: A Fast Dynamic Language for Technical Computing".
arXiv:1209.5145, 27 pages; initial design document