How about this macro:

macro run(file, args...)
    return esc(:(ARGS = $args; include($file)))
end

For example:

---------------------------------------------
$ cat ./test.jl 
#!/usr/bin/julia

for a in ARGS
println(a)
end

$ julia
...
julia> macro run(file, args...)
           return esc(:(ARGS = $args; include($file)))
       end

julia> @run "test.jl" 1 2 3 4
1
2
3
4
---------------------------------------------

Does that do what you want?

Cheers,
Daniel.

On Thursday, 30 October 2014 10:22:59 UTC+1, Martin Klein wrote:
>
> Hi,
>
> when using Python I usually execute my programs within IPython by using 
> the %run command, which executes a given script with the given arguments, 
> but keeps all of the defined variables in the namespace after execution. 
> Unfortunately, I couldn't find any fully equivalent command for the Julia 
> REPL. I know about include(), but I couldn't figure out how to give command 
> line arguments to the script, which I want to run (i.e. the stuff which is 
> saved in the ARGS array).
>
> Additionally, IPython provides the handy %pdb command, which automatically 
> opens the ipython debugger when an exception is thrown (i.e. it's an 
> exception breakpoint). This is also a very nice feature to quickly 
> investigate errors. I know that Julia doesn't have a full-blown debugger 
> yet (besides debug.jl), but nevertheless this would be a nice future 
> feature for the REPL once there is a Julia debugger.
>
> Alternatively, I would be interested in your current first-run-and-debug 
> workflow. I like to write my code in vim but ifter execution I want to 
> directly investigate the state of my program using the REPL.
>
> Best,
> Martin
>

Reply via email to