ugh it posted accidentally
Let's try this again:

Trying to get the command line style syntax working. 

Somewhere on StackOverflow someone suggested this way of doing things:

module M 
end

if length(ARGS) > 0 && ARGS[1] == "--run"
  using M
  # do whatever
end

however, if I write a simple example (in it's own file) like:

if length(ARGS) > 0 && ARGS[1] == "--run"
  using FactCheck
  for i in [1,2,3]
    println(i)
  end
end

I get the following error:

ERROR: LoadError: error compiling anonymous: unsupported or misplaced 
expression "using" in function anonymous

 in include at /usr/local/Cellar/julia/0.4.0/lib/julia/sys.dylib

 in include_from_node1 at /usr/local/Cellar/julia/0.4.0/lib/julia/sys.dylib

 in process_options at /usr/local/Cellar/julia/0.4.0/lib/julia/sys.dylib

 in _start at /usr/local/Cellar/julia/0.4.0/lib/julia/sys.dylib

while loading /Users/Vishesh/repos/learning/julia/test.jl, in expression 
starting on line 3

The only way to make this work is like:

if length(ARGS) > 0 && ARGS[1] == "--run"
  using FactCheck
  eval(:(
  for i in [1,2,3]
    println(i)
  end
  ))
end


which seems excessive. 
Basically, I can do a regular function call after a using statement, so 
using M; println("hello world") is fine, but using M; for ... end doesn't 
work.

ideas?
Vishesh

On Tuesday, December 8, 2015 at 3:43:55 PM UTC-8, [email protected] wrote:
>
> Hi all,
>
> Trying to get the command line style syntax working. 
>
> Somewhere on StackOverflow someone suggested this way of doing things:
>
> module M 
> end
>
> if length(ARGS) > 0 && ARGS[1] == "--run"
>   using M
>   # do whatever
> end
>
> however, if I write a for loop like
>
> if ...
>   using M
>   for l in readlines(STDIN)
>
> end
>
>
>

Reply via email to