This could be useful to me :)

I have a couple of functions that require JuMP but I don't want to add JuMP 
to my REQUIRE file. My usual tactic of checking isdefined(:JuMP) won't work 
because JuMP uses macros that are evaluated prior to runtime. However, I 
was unable to make the following code work:

@cond (isdefined(:JuMP)) begin
function something_that_requires_jump(a...)
...
end # function
end # macro

Is there an accepted way to do conditional includes of packages that 
contain macros?

On Thursday, November 12, 2015 at 4:37:43 AM UTC-8, andrew cooke wrote:
>
>
> ah, great.  i won't make a new package then.  thanks.
>
> On Thursday, 12 November 2015 09:30:21 UTC-3, Yichao Yu wrote:
>>
>> https://github.com/JuliaLang/julia/issues/7449 
>> https://github.com/JuliaLang/Compat.jl/pull/131 
>> https://github.com/JuliaLang/julia/issues/5892 
>>
>> On Thu, Nov 12, 2015 at 7:23 AM, andrew cooke <and...@acooke.org> wrote: 
>> > 
>> > when you're writing code that uses macros, supporting different 
>> versions of 
>> > julia seems to be more complex than normal.  in particular, things 
>> like: 
>> > 
>> > if VERSION > XX 
>> >     # code with macros here 
>> > end 
>> > 
>> > don't work as expected, because macro expansion occurs before runtime 
>> > evaluation.  so the macros are expenaded whatever version. 
>> > 
>> > given that, i have found this simple macro to be useful; 
>> > 
>> > macro cond(test, block) 
>> >     if eval(test) 
>> >         block 
>> >     end 
>> > end 
>> > 
>> > @cond VERSION >= v"0.4" begin 
>> >      # code with macros here 
>> > end 
>> > 
>> > anyway, my questions are: (1) is the above sensible and (2) does this 
>> > already exist? 
>> > 
>> > thanks, 
>> > andrew 
>> > 
>>
>

Reply via email to