3.4 Variables
A variable is a name that will be associated to a value through a memory space; these are case-sensitive.
3.4.1 Defining variables
Variables are defined and modified using =
, see some examples below.
3.4.2 Define more than one variable
More that one variable can be defined using tuples syntax.
3.4.3 Allowed variable names
- Unicode names can be used. This is an interesting Julia feature.
- Built-in constants or functions cannot be replaced after being used.
pi; pi = 3
# ERROR: cannot assign a value to variable MathConstants.pi from module Main
# Stacktrace:
# [1] top-level scope at REPL[95]:1
sqrt(4); sqrt = 4
# ERROR: cannot assign a value to variable Base.sqrt from module Main
# Stacktrace:
# [1] top-level scope at REPL[97]:1
- Built-in keywords cannot be modify.
- Some Julia naming conventions:
- Use lower case for variables, functions, and macros (e.g.
name = "Julia"
). - Underscore (
_
) use is discouraged (e.g.lastname = "Montalvan"
). - Use uper camel case for
Types
andModules
. - Use
!
at the end of a function name when it mutates its arguments.
- Use lower case for variables, functions, and macros (e.g.