No prob.

— Mike
​


On Tuesday, 30 December 2014 23:13:01 UTC+2, Ismael VC wrote:
>
> Thank you Michael I got it!
>
> julia> macro dynamic_import(modules)
>            ex = Expr(:toplevel)
>            names = map(m -> symbol(split(m, '.')[1]), modules.args)
>            for name in names
>                push!(ex.args, Expr(:import, name))
>            end
>            return ex
>        end
>
> julia> @dynamic_import ["Newton.jl", "MyTest.jl"]
>
> julia> Newton
> Newton
>
> julia> MyTest
> MyTest
>
>
>
> El martes, 30 de diciembre de 2014 15:05:34 UTC-6, Michael Hatherly 
> escribió:
>>
>> You don’t need the quote ... end block since you’re creating the 
>> expression manually using Expr objects.
>> Removing that and changing $modules to modules.args should work alright 
>> I think.
>>
>> — Mike
>> ​
>>
>>
>> On Tuesday, 30 December 2014 22:52:55 UTC+2, Ismael VC wrote:
>>>
>>> I get a different expression from parsing foo:
>>>
>>> julia> versioninfo()
>>> Julia Version 0.3.3
>>> Commit b24213b (2014-11-23 20:19 UTC)
>>> Platform Info:
>>>   System: Linux (i686-pc-linux-gnu)
>>>   CPU: Intel(R) Atom(TM) CPU N570   @ 1.66GHz
>>>   WORD_SIZE: 32
>>>   BLAS: libblas
>>>   LAPACK: liblapack
>>>   LIBM: libm
>>>   LLVM: libLLVM-3.3
>>>
>>>
>>> julia> parse("import foo")
>>> :($(Expr(:import, :foo)))
>>>
>>> julia> parse("import foo, bar, baz")
>>> :($(Expr(:toplevel, :($(Expr(:import, :foo))), :($(Expr(:import, :bar
>>> ))), :($(Expr(:import, :baz))))))
>>>
>>> This is returning the needed expression, but it's returning it like a 
>>> function instead of executing it:
>>>
>>> julia> macro dynamic_import(modules)
>>>            quote
>>>                ex = Expr(:toplevel)
>>>                names = map(m -> symbol(split(m, '.')[1]), $modules)
>>>                for name in names
>>>                    push!(ex.args, Expr(:import, name))
>>>                end
>>>                return ex
>>>            end
>>>        end
>>>
>>> julia> @dynamic_import ["Newton.jl", "MyTest.jl"]
>>> :($(Expr(:toplevel, :($(Expr(:import, :Newton))), :($(Expr(:import, :
>>> MyTest))))))
>>>
>>> I thought I almost got this! :D
>>>
>>>
>>>
>>> El lunes, 29 de diciembre de 2014 21:45:45 UTC-6, Joshua Adelman 
>>> escribió:
>>>>
>>>> I'm attempting to do some dynamic module loading and subsequent 
>>>> processing and can't quite figure something out. I think I have a 
>>>> reasonable (albeit maybe not idiomatic) mechanism for dynamically 
>>>> importing 
>>>> a set of modules. See my stackoverflow question and the subsequent self 
>>>> answer:
>>>>
>>>> http://stackoverflow.com/q/27696356/392949
>>>>
>>>> My next question is, after I've dynamically/programmatically imported a 
>>>> bunch of modules, is there a way of iterating over that set of modules? 
>>>> Specifically, if I store the module names as strings (e.g. ["mod00", 
>>>> "mod01", "mod02"]) and each module contains some function `func` that 
>>>> isn't 
>>>> exported, how would I call `mod00.func()` if I only know the string 
>>>> "mod00"? I think this comes down to converting the string to a Module 
>>>> type, 
>>>> but I'm not sure and haven't come up with something workable after a few 
>>>> passes through the docs.
>>>>
>>>> Any suggestions would be very much appreciated.
>>>>
>>>> Josh
>>>>
>>>

Reply via email to