Am Donnerstag, 30. Oktober 2014 14:42:28 UTC+1 schrieb Daniel Carrera:
>
> 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?
>
 
Yes, almost. Thank you for this nice small solution. I still have to 
enclose most of the arguments with quotation marks though, which is a minor 
annoyance. I'm quite sure that one could extend the macro to automatically 
convert all given arguments to strings. When I find the time for it I will 
use this as an excuse to finally try to learn Julia's metaprogramming 
capabilities.

I would also suggest that something like that should be added to Base.

Thanks!
Martin
 

>
> 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