Thank you -- clearly given.

On Friday, October 23, 2015 at 12:07:07 PM UTC-4, Steven G. Johnson wrote:
>
>
>
> On Friday, October 23, 2015 at 8:37:58 AM UTC-4, Jeffrey Sarnoff wrote:
>>
>> I want to allow users of my Float12x module the choice of faster or more 
>> precise trig
>>    (at the moment, 103bits over 0..2pi is ~30% faster than 106bits; the 
>> more precise version also handles larger arguments).
>> The choice needs to be made before the using statement, as it governs the 
>> inclusion of either one of two small source files.
>>
>
> It would be better to refactor your code so that the choice can be made 
> dynamically, after the module is loaded.
>
> However, if it is really impossible to do this dynamically, then this kind 
> of "static" choice would normally be made at Pkg.build time, and a common 
> mechanism for specifying it would be an environment variable.   The 
> advantage of using Pkg.build is that then your module can be precompiled.   
> The procedure I've used is something like:
>
> 1) create a deps/build.jl file that looks at ENV["FASTTRIG"] (or whatever) 
> and spits out:
>
>        a) a deps/deps.jl file with a constant like `const FASTTRIG = true`
>
>        b) a deps/FASTTRIG file to save the FASTRIG setting for the next 
> time the file is built.  This way, if your package is rebuilt on e.g. a 
> Pkg.update, you won't "forget" the user's preference.    i.e. you would 
> read ENV["FASTTRIG"] by something like:
>                   get(ENV, "FASTTRIG", isfile("FASTTRIG") ? 
> readchomp("FASTTRIG") : "no")
>
> 2) in your main module file, do
>
> const depfile = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
>
> isfile(depfile) || error("Float12x not properly installed. Please run 
> Pkg.build(\"Float12x\")")
>
> include(depfile) # generated by Pkg.build("Float12x")
>
>
> and then use the value of FASTTRIG to decide how to proceed.
>
>
> 3) Tell your users to do
>
>
> ENV["FASTTRIG"] = "yes" or "no"
>
> Pkg.build("Float12x")
>
>
> when they want to change the setting.
>

Reply via email to