On 31 October 2014 03:29, David P. Sanders <[email protected]> wrote:

>
> Does the following count as a fragile hack? (Probably yes!)
>
> macro run(file, args...)
>     args = [file, args...]
>     return esc(:(ARGS = map(string, $args)[2:end];
> include(string($args[1]))))
> end
>


IMO, yes.



> julia> @run test.jl a b c
> a
> b
> c
>
> Though you must do
>
> julia> @run "/Users/david/test.jl" a b c
> a
> b
> c
>
> with quotes, which is what I guess you referred to with "parsed form"?
>


The point is that Julia will parse the entire line and form a parse tree
before it begins to interpret the instruction. Therefore, the @run line has
to parse correctly as valid Julia syntax.

If you want to type fewer quotation marks, one could make a macro that
takes everything as one string:

@run "test.jl  --fast a -r 3"

The macro can split the string along the spaces.

Cheers,
Daniel

Reply via email to