May 14, 2021 Julia
Julia's installation, whether using a compiled program or compiling it yourself from source code, is simple. Follow the instructions here to download and install.
Using an interactive session (also known as repl) is the easiest way to learn Julia:
$ julia
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "help()" to list help topics
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.3.0-prerelease+3690 (2014-06-16 05:11 UTC)
_/ |\__'_|_|_|\__'_| | Commit 1b73f04* (0 days old master)
|__/ | x86_64-apple-darwin13.1.0
julia> 1 + 2
3
julia> ans
3
You
^D
interactive session by
ctrl
the key plus
d
key, or by entering
quit()
I
n interactive mode,
julia
a banner and prompts the user to enter it. O
nce the user enters a complete expression,
1 + 2
and then pressEs, the interactive session evaluates the expression and returns the value. I
f you enter an expression with a sign at the end, its value is not displayed. T
he value of the variable
ans
is the value of the last evaluated expression, regardless of whether the last time it was displayed or not.
Variable
ans
only available for interactive sessions and not for Julia code that runs in other ways.
If you want to run code written in the source file file.jl, you
include("file.jl")
To run code in non-interactive mode, you can think of it as the first argument on the Julia command line:
$ julia script.jl arg1 arg2...
As this example shows, julia is followed by a command-line argument, which is considered a command-line argument for the program script.jl. T hese parameters are passed using the global variable ARGS. U sing the -e option, you can also set the ARGS parameter on the command line. The passed parameters can be printed by:
$ julia -e 'for x in ARGS; println(x); end' foo bar
foo
bar
You can also put the code in a script and run it:
$ echo 'for x in ARGS; println(x); end' > script.jl
$ julia script.jl foo bar
foo
bar
Julia can
-p
mode with the -p or
--machinefile
option.
-p n
initiates an additional n work
--machinefile file
initiates a work process for each line of file file. A
machine defined by file must be accessible via a passwordless ssh, and Julia on each machine should be installed in
[user@]host[:port] [bind_addr]
user
defaults to the current user and
port
defaults to the standard ssh port.
Alternatively, in the case of a multi-network host, the
bind_addr
used to specify the interface precisely.
If you want Julia to run some code at startup, you can put the code
~/.juliarc.jl
$ echo 'println("Greetings! 你好! 안녕하세요?")' > ~/.juliarc.jl
$ julia
Greetings! 你好! 안녕하세요?
...
Running Julia has a variety of options:
julia [options] [program] [args...]
-v, --version Display version information
-h, --help Print this message
-q, --quiet Quiet startup without banner
-H, --home <dir> Set location of julia executable
-e, --eval <expr> Evaluate <expr>
-E, --print <expr> Evaluate and show <expr>
-P, --post-boot <expr> Evaluate <expr> right after boot
-L, --load <file> Load <file> right after boot on all processors
-J, --sysimage <file> Start up with the given system image file
-p <n> Run n local processes
--machinefile <file> Run processes on hosts listed in <file>
-i Force isinteractive() to be true
--no-history-file Don't load or save history
-f, --no-startup Don't load ~/.juliarc.jl
-F Load ~/.juliarc.jl, then handle remaining inputs
--color={yes|no} Enable or disable color text
--code-coverage Count executions of source lines
--check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)
--int-literals={32|64} Select integer literal size independent of platform
In addition to this manual, there are a number of other resources: