官术网_书友最值得收藏!

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 0.3.2+2. (The versioninfo()function in REPL is more detailed, the VERSION constant gives you only the version number: v"0.3.2+2"). 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 (on Windows, use " instead of the ' character).

Some other options 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 as follows:

for arg in ARGS
  println(arg)
end

The julia args.jl 1 Dart C command prints out 1, Dart, and C on consecutive lines.

A script file also can execute other source files by including them in the REPL; for example, main.jl contains include("hello.jl") that will execute the code from hello.jl when called with julia main.jl.

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

主站蜘蛛池模板: 玉环县| 九台市| 沂南县| 镇康县| 华蓥市| 昭觉县| 巴楚县| 大渡口区| 来凤县| 厦门市| 千阳县| 上犹县| 丹巴县| 建阳市| 阿尔山市| 竹北市| 邹城市| 鹤庆县| 宜阳县| 习水县| 林周县| 察隅县| 辛集市| 靖远县| 木兰县| 连南| 容城县| 扶绥县| 商河县| 龙泉市| 阿克陶县| 台南市| 诏安县| 环江| 慈利县| 泽库县| 西盟| 德清县| 海淀区| 东平县| 兴安县|