On Fri, May 13, 2016 at 8:37 AM, Tom Breloff <t...@breloff.com> wrote:
> I think this will work:
>
>> for (fn, arg) = ((:toucha, "a"), (:touchb, "b"))
>>     cmd = `touch $arg`
>>     @eval $fn() = run($cmd)

I believe `` @eval $fn() = run($`touch $arg`) `` also works

>> end
>
>
>
> On Fri, May 13, 2016 at 7:34 AM, Andrew Gibb <andrew.g...@gmail.com> wrote:
>>
>> I'm trying to use metaprogramming to create two functions. Each of which
>> includes a similar, long, call to run(). The calls are not quite identical.
>> Some flags have different arguments, and some are only present on one call.
>> I can't work out how to get expression interpolation to happen within
>> command interpolation. For example:
>>
>> for (fn, arg) = ((:toucha, "a"), (:touchb, "b"))
>>     #@eval ($fn)() = run(`touch $arg`)
>>     @eval ($fn)() = run(`touch $(@eval ($arg))`)
>> end
>>
>> In the first of these cases, the result for toucha is
>> toucha() = run(`touch $arg`)
>>
>> and similarly for the second result, the parsing character $ is ignored by
>> the eval. Is there a way to get this to instead return
>> toucha() = run(`touch a`)
>>
>> ?
>
>

Reply via email to