Review / Clarifications
Contents
Review / Clarifications¶
Working With Julia Files / Binder / Jupyter / VSCode¶
Anatomy of a Julia File¶
As an example lets look at anatomy_of_julia.jl
The first thing to know is that the computer reads the lines of code in the julia file from top to bottom and executes the code in that order.
Top of file¶
At the very top of the file puts two types of statements to allow the file to use code from other files, julia modules, or external packages.
using statements: These bring in functionality from external sources to your code base (julia modules, external packages) include statements: These bring in functionality from other files in your code. include(“../module2/hello.jl”)
Middle of file¶
This is where we define functions, shared variables etc.
Bottom of file “Script” portion (optional)¶
At the bottom you can write lines of code that will be executed. This is only necessary if that file is going to be something you want to execute every time that file is used. This is where we “use” the functionality defined in the functions above or in the functionality we have included from other places. This code must be below any function it is using or importing.
For files that are just defining functions or structs you would not have this script section. An example of this is hello.jl which just defines some functions that can be used elsewhere
Binder¶
The easiest way to run a file from binder (jupyterhub) is to use an include statement
include("path to file here")
This will load the functions and run any scripting lines.
How to run code + visual debugging in VSCode¶
See this documentation for details: https://code.visualstudio.com/docs/languages/julia
Basics of Julia Syntax
Math Functions Printing Loops Vectors/Matrices