On Thursday, 28 January 2016 08:12:06 UTC-5, Stefan Karpinski wrote: > > Please try to avoid this business of creating the same conversation in > three places. > > On Thu, Jan 28, 2016 at 8:10 AM, Stefan Karpinski <[email protected] > <javascript:>> wrote: > >> >> http://stackoverflow.com/questions/35051773/create-local-variables-programmatically-from-a-dictionary-in-julia >> >> On Thu, Jan 28, 2016 at 8:10 AM, Stefan Karpinski <[email protected] >> <javascript:>> wrote: >> >>> https://groups.google.com/forum/#!topic/julia-users/axwQqFeIlCQ >>> >>> On Wed, Jan 27, 2016 at 11:05 PM, Yichao Yu <[email protected] >>> <javascript:>> wrote: >>> >>>> On Wed, Jan 27, 2016 at 9:47 PM, Fady Shoukry <[email protected] >>>> <javascript:>> wrote: >>>> > >>>> >> >>>> >> Depending on what API JuMP provide and what API you want to provide, >>>> I >>>> >> think you should either keep the dict (if JuMP can handle it) or use >>>> >> meta programing to construct an AST/function based on the user input >>>> >> and evaluate that. >>>> > >>>> > >>>> > Thanks for the quick reply. Could you elaborate on that last part >>>> regarding >>>> > constructing an AST/function (with an example if possible)? >>>> > >>>> >>>> A simple example that hopefully shows what I meant, >>>> >>>> >>>> ``` >>>> julia> vars = [:a, :b] >>>> 2-element Array{Symbol,1}: >>>> :a >>>> :b >>>> >>>> julia> expr = :(a + b) >>>> :(a + b) >>>> >>>> julia> function make_function(name, vars, expr) >>>> :(function $name() >>>> $([:($v = 1) for v in vars]...) >>>> $expr >>>> end) >>>> end >>>> make_function (generic function with 1 method) >>>> >>>> julia> func_ast = make_function(:new_function, vars, expr) >>>> :(function new_function() # none, line 3: >>>> a = 1 >>>> b = 1 # none, line 4: >>>> a + b >>>> end) >>>> >>>> julia> eval(func_ast) >>>> new_function (generic function with 1 method) >>>> >>>> julia> new_function() >>>> 2 >>>> >>>> julia> @code_warntype new_function() >>>> Variables: >>>> a::Int64 >>>> b::Int64 >>>> >>>> Body: >>>> begin # none, line 3: >>>> a = 1 >>>> b = 1 # none, line 4: >>>> return (Base.box)(Int64,(Base.add_int)(a::Int64,b::Int64)) >>>> end::Int64 >>>> ``` >>>> >>> >>> >> > Apologies, the second Google groups post was posted by mistake and is incomplete and the stackoverflow question (by a colleague of mine) was in hopes to get as many opinions as possible, everyone is very responsive and see I see that was unnecessary, my bad.
Thanks for the valuable input, I will look further into the JuMP API as per your comment. Otherwise, it saves time to know that this is not doable by design. Just out of curiosity, is there a specific reason why this is not a feature you would want to allow?
