Julia codegeneration with global function

Viewed 273

julia 0.5.1

I want to create a function inside a quote that can be used after the specified macro has been used. Here is an example of what I mean

macro wat()
  quote
    type Foo end
    global bar() = begin end
    global function bar2()
    end
    type Baaz end
  end
end

@wat
Foo()
Baaz()
bar()
bar2()

Now when I run this the last line crashes, because bar2 is undefined. I do not understand why because in my understanding bar() and bar2() should be equal and bar is just syntactic sugar for bar2. But they are apparently not equal and I do not understand why the one works and other does not.

Secondly is there a way to define bar and bar2 inside that quote without the global-keyword and still being available after the macro has been executed?

My motivation for wanting the bar2 notation is that I can specify a return-type with this syntax.

global bar3()::Void = begin end

Is not allowed syntax.

1 Answers
Related