- Julia 1.0 Programming Complete Reference Guide
- Ivo Balbaert Adrian Salceanu
- 357字
- 2021-06-24 14:21:39
Startup options and Julia scripts
Without any options, the julia command starts up the REPL environment. A useful option to check your environment is julia -v. This shows Julia's version, for example, julia version 1.0.0. (The versioninfo()function in REPL is more detailed, and the VERSION constant only gives you the version number: v"1.0.0"). An option that lets you evaluate expressions on the command line itself is -e, for example:
julia -e 'a = 6 * 7;
println(a)'
The preceding commands print out 42 (this also works in a PowerShell window on Windows, but in an ordinary Windows Command Prompt, use " instead of the ' character).
Some other options that are useful for parallel processing will be discussed in Chapter 9, Running External Programs. Type julia -h for a list of all options.
A script.jl file with Julia source code can be started from the command line with the following command:
julia script.jl arg1 arg2 arg3
Here, arg1, arg2, and arg3 are optional arguments to be used in the script's code. They are available from the global constant ARGS. Take a look at the args.jl file, which contains the following:
for arg in ARGS println(arg) end
The julia args.jl 1 Red C command prints out 1, Red, and C on consecutive lines.
A script file can also execute other source files by including them in the REPL; for example, main.jl contains include("hello.jl"), which will execute the code from hello.jl when called with julia main.jl.
Sometimes, it can be useful to know when code is executed interactively in the REPL, or when started up with the Julia VM with the julia command. This can be tested with the isinteractive() function. The isinteractive.jl script contains the following code:
println("Is this interactive? $(isinteractive())")
If you start this up in the REPL with include("isinteractive.jl"), the output will be Is this interactive? true.
When started up in a Terminal window as julia isinteractive.jl, the output is Is this interactive? false.
- 深度學習經典案例解析:基于MATLAB
- Pandas Cookbook
- Manga Studio Ex 5 Cookbook
- Rake Task Management Essentials
- 精通軟件性能測試與LoadRunner實戰(第2版)
- Java程序設計與實踐教程(第2版)
- C#程序設計
- Spring核心技術和案例實戰
- C#應用程序設計教程
- Terraform:多云、混合云環境下實現基礎設施即代碼(第2版)
- Access 2010數據庫應用技術實驗指導與習題選解(第2版)
- 原型設計:打造成功產品的實用方法及實踐
- Android初級應用開發
- 關系數據庫與SQL Server 2012(第3版)
- Swift 2 Design Patterns