To make your macro hygienic, you need to do this:
macro profileview(ex)
quote
Profile.clear()
@profile $(esc(ex))
using ProfileView
ProfileView.view()
end
end
There also may be a problem with having `using ProfileView` emitted in a
macro like this, but fixing the hygiene issue is a good first thing to try.
On Tue, Aug 26, 2014 at 12:33 PM, Ethan Anderes <[email protected]>
wrote:
> Hi Folks,
> I’m trying to write a macro for my .juliarc.jl file which lays down the
> syntax for generating a ProfileView. I use ProfileView infrequent enough
> that whenever I use it I need to refer to the github page. To fix this I
> want to write something really quick and easy but I’m running into problems
> with the following macro.
>
> macro profileview(ex)
> quote
> Profile.clear()
> @profile $ex
> using ProfileView
> ProfileView.view() # <---- this seems to be the problem
> end
> end
>
> I get the following error
>
> julia> @profileview sin(10)
> ERROR: error compiling anonymous: unsupported or misplaced expression using
> in function anonymous
>
> I don’t have any experience with macros so I can’t tell what I’m doing
> wrong here. I would like to be able to write @profileview foo(x) and have
> the profile window pop up. Any suggestions?
>
> Thanks,
> Ethan
>
>