Regarding your SO question, the suggested way to do this is with a macro,
but (as you observed) it is a bit tricky. Whenever I try to do this I have
to remind myself how it works by using parse and dump to see how the
expression should look:

```
julia> parse("import foo")
:(import foo)

julia> dump(x)
Expr
  head: Symbol import
  args: Array(Any,(1,))
    1: Symbol foo
  typ: Any
```

So then I can duplicate that and eval it, for example:
```
julia> eval(Expr(:import, :Color))
```

module contains some function `func` that isn't exported, how would I call
> `mod00.func()` if I only know the string "mod00"


```
julia> module mod00
       func() = println("hello")
       end

julia> eval(symbol("mod00")).(symbol("func"))()
hello
```

I'm not sure what the overall goal is here, but just beware that eval
should only be used like this for testing purposes or else your code will
be slow.


On Mon, Dec 29, 2014 at 10:45 PM, Joshua Adelman <[email protected]>
wrote:

> 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