although it's not clear that's much better than if USE_A using A else using B end
really... On Sunday, 13 September 2015 21:59:37 UTC-3, andrew cooke wrote: > > > the following works.. > > first, defining module AB: > > module A > export foo > foo() = println("a") > end > > module B > export foo > foo() = println("b") > end > > module AB > if Main.USE_A > using A > else > using B > end > export foo > end > > that depends on Main.USE_A, where Main is the initial module when things > start up, so then you can do: > > USE_A = true > > include("ab.jl") > > using AB > foo() > > which prints "a". > > no idea if this is considered kosher... > > andrew > > > > > On Sunday, 13 September 2015 21:45:57 UTC-3, andrew cooke wrote: >> >> >> i don't know of a good way to do this. >> >> really, parameterised modules would be great. >> >> the simplest thing i can think of is if modules are first class and using >> etal can take an expression, but the following doesn't run: >> >> module A >> foo() = println("a") >> end >> >> module B >> foo() = println("b") >> end >> >> module AB >> m(x) = x ? A : B >> end >> >> using AB >> using m(true) >> foo() # wouldn't it be nice if this printed "a"? >> >> andrew >> >> >> On Sunday, 13 September 2015 19:33:16 UTC-3, Seth wrote: >>> >>> Hi all, >>> >>> I'd like to track a setting throughout my module (that will cause the >>> [transparent] dispatch of either single-threaded or parallel versions of >>> many different functions). Is there a more Julian way of doing the >>> following? This seems inelegant: >>> >>> _parallel = false # start off without parallelism - user calls >>> parallelize() to set/unset. >>> >>> function parallelize(p::Bool=true) >>> global _parallel = p >>> end >>> >>> >>> function foo(a::Int) # there will be many functions like this >>> if _parallel >>> _foo_parallel(a) >>> else >>> _foo_singlethread(a) >>> end >>> end >>> >>>