Seems like a macro hygiene issue, in two ways :)

   - It's a bug in macro hygiene that you don't get that error without the 
   inner constructor (apparently it doesn't consider type definition as a form 
   of assignment to the named symbol).
   - It can be fixed by escaping the name of the type: n = esc(name.args[1]) 
   to circumvent hygienization for it.

Btw, any reason that you want to supply a quoted symbol to the macro? It 
seems more straightforward with

macro mymac(name::Symbol)
    n = esc(name)
    quote
        type $n
            x::Int64
            $n(num::Int64) = new(num)
        end
    end
end

@mymac(mynewtype)
println(mynewtype)


On Thursday, 2 October 2014 14:05:03 UTC+2, Ariel Keselman wrote:
>
> working on the GeometricPredicates package, I want to generate a few 
> mostly similar types like this:
>
> macro mymac(name)
>     n = name.args[1]
>     quote
>         type $n
>             x::Int64
>             $n(num::Int64) = new(num)
>         end
>     end
> end
>
> @mymac(:mynewtype)
> println(mynewtype)
>
> It raises an error (mynewtype is undefined) unless I comment out the inner 
> constructor. Is this a bug? I couldn't find anything similar in the 
> mailing lists
>
> any thoughts? Thanks!
>
>

Reply via email to