Sage-Code Laboratory
index<--

Julia Syntax

The syntax is minimalist and is based on English keywords. Therefore Julia is very readable compared to curly braced languages. You can learn Julia to proficient level in less then one week as your first computer language.

Julia language has a very polished syntax. It eliminate annoying elements found in other languages while implementing most of the important features. Having a simplified syntax matter. This is one of the simplistic language out there that have significant performance and power. This is one of the reason we recommend Julia to beginners.

Syntax characteristics

Example of program:

# first julia program
print("Hello World")

Comments

Line comments is starting with symbol "#" exactly like in Python. Nested comments are possible in Julia. To create a multi-line comment in Julia we use two symbols: #= …. =#. That is unconventional but has a logic behind. We can create a separator line like this:


#================================#
# This is a comment demo
#================================#

Keywords

Next I will list several Julia keywords in logical order but not all of them. You may encounter other keywords in practice. I will try to add more keywords here when I fully understand them. Remember this article is just an introduction tutorial not a reference document.

Keyword Description
true The constant true is a Boolean value
false The constant false is a Boolean value
maybe Not a keyword 🙂 just teasing you
constant Define a constant usually a global
global Used in local scope to show that a variable is not local
local Used in local scope to force a variable to be local and hide a global variable
begin Mark the beginning of a compound expression block "begin … end"
let Mark the beginning of a let block: "let … end"
end Mark the end of a block, function or module
function Create a function
module Create a module
return Create an exit point from a function and return a result
import Import into a module public members from another module
export Export module public members to be imported into another module
if Decision statement
else Alternative block for false condition
elseif Alternative block for second condition
while Start a while loop "while … end"
for Start a for loop: "for … in … end"
in Used with for to iterate over a range or collection
break Stop a while or a for loop
continue Shortcut a loop and continue with next iteration
print Print a message to console
println Print a message to console and add end of line
try Start a block of code that may rise exceptions
catch Start exception handling block
finally Is the final part that execute not matter what for a try block
throw() This is a standard function to create an exception
error() Also create an exception of type ErrorException
abstract Define an abstract type
primitive Used to create a primitive type
type Used with abstract or primitive keyword to create a type
struct Create a structure like a record (immutable)
mutable Used with struct to create a mutable struct
union Used to create a union type
typeof() This is a function used to display type information about a variable
isa() A function that return true or false about type of a variable
supertype() Extract the supe-type information for a type
Nullable{} Create a null-able type
isnull() Check if a null-able type is null
macro block of code execute when code is parsed (used to generate code), invoke macro with @ operator.
quote expression that span multiple lines used as alternative to quote operator ":"
eval() used in meta-programming to evaluate a string expression

Read next: Type System