Orhan Abar
Orhan Abar

Reputation: 133

Isn't there any way to pass arguments in REPL mode?

I couldn’t run my program from the REPL. When I try this:

julia> ARGS = ["hello", "world"] include("test.jl")
error: ERROR: syntax: extra token "include" after end of expression

How can you make it 2 lines: If I try to run first:

ARGS = ["hello", "world"] 
Error: ERROR: cannot assign variable Base.ARGS from module main

But command line is working without any problem

I tried:

julia> include("test.jl", ARGS = ["hello", "world"])
julia> include("test.jl","hello", "world")

none of them is working.

Upvotes: 2

Views: 1061

Answers (1)

Bill
Bill

Reputation: 6086

ARGS, the array of String command line arguments to Main loaded when Julia is run at the REPL is read-only. So you cannot re-assign it.

You can create a new module at the REPL and run your program via include in the namespace of the module, though, because Main.ARGS is not the same as another module's ARGS.

Let's say test.jl contains the single line

println(prod(ARGS))

and so then you may type this at the REPL command line (including use of the Enter key):

julia> module test
       ARGS=["hello", "world"]
       include("test.jl")
       end

The output should then be:

helloworld
Main.test

Upvotes: 3

Related Questions