You are calling `symbol` on an object, which results in a fully-qualified
name when called inside a module:

julia> module Foo
       abstract a
       f() = symbol(a)
       end

julia> Foo.f()

symbol("Foo.a")


(or try adding `@show superSymb` inside your function)

Creating a symbol from a type instance here isn't really necessary because
you can splice in `$supertype` directly. (see the "Metaprogramming" section
of the manual)

Having said that: calling a function to create a type is not
recommended/idiomatic. Instead, you could call `@eval` at the top level in
your module (possibly in a for loop). There are a handful of examples of
this in base, for example in "linalg/triangular.jl".




On Sun, Oct 11, 2015 at 12:01 PM, Andrew Keller <andrew.keller...@gmail.com>
wrote:

> I'm using Julia 0.4.0 on Mac OS X 10.10.5. I'd like to put some code into
> a module, but I'm having some trouble with namespaces. The following fails
> (`UndefVarError: test.a not defined`) when enclosed inside `module test`.
> When outside the module, e.g. pasted into the REPL, the code works fine.
> Could someone point me to relevant reading material or explain what is
> going on?  It seems I can avoid the problem by putting the string "a" in
> the dictionary instead of the abstract type, but I want to know why I am
> unable to do things as written. Thank you for your patience as I am new to
> the language.
>
> module test
>
> abstract a
>
> dict = Dict("key" => a)
>
> function createType(typeName::ASCIIString,supertype::DataType)
>
> typeSymb = symbol(typeName)
> superSymb = symbol(supertype)
> @eval immutable ($typeSymb){T} <: $superSymb
>
> num::Float64
>
> end
>
> end
>
> createType("b",dict["key"])
>
> end
>

Reply via email to