Overwrite `ARGS` after reading


#1
julia> ARGS = 2
2

(fresh session)

julia> ARGS
0-element Array{String,1}

julia> ARGS = 2
ERROR: cannot assign variable Base.ARGS from module Main
Stacktrace:
 [1] top-level scope at none:0

Is it possible to set a global ARGS = 2 after reading ARGS (i.e. Base.ARGS)?

(Probably not?)


#2

Ok, I guess I can do

julia> Base.ARGS
0-element Array{String,1}

julia> ARGS = 2
2

Nevermind.


#3

Do you want to modify Base.ARGS or work with another variable that is incidentally named ARGS but is otherwise unrelated? If the first, you can do the usual vector manipulations, eg

push!(Base.ARGS, "--runfaster=please")

#4

The latter, but thanks anyway!


#5

Defining your own local variable or module global variable named ARGS is not a problem. The only problem arises in the REPL or similar contexts where Base.ARGS has already been imported and bound to a local variable ARGS.

For example:

julia> module Foo
       const ARGS = 2
       end
Main.Foo

julia> Foo.ARGS
2

or

julia> let ARGS = 3
           println("ARGS = $ARGS")
       end
ARGS = 3

or

julia> function foo()
           ARGS = 4
           return ARGS
       end
foo (generic function with 1 method)

julia> foo()
4