Right, I had tried using esc (even though I don’t really understand why I 
need it) but I still get an error.

Here’s the macro (I took out using ProfileView)

macro profileview(ex)
    quote
        Profile.clear()
        @profile $(esc(ex))
        # using ProfileView
        ProfileView.view()
    end
end

and here is the error

julia> using ProfileView

julia> @profileview sin(10)
WARNING: There were no samples collected. Run your program longer (perhaps by
running it multiple times), or adjust the delay between samples with
Profile.init().
ERROR: `start` has no method matching start(::Nothing)
 in view at /Users/ethananderes/.julia/v0.3/ProfileView/src/ProfileView.jl:116 
(repeats 2 times)
 in anonymous at none:6

Maybe this is a ProfileView thing? Anyhoo, thanks.

Ethan

On Tuesday, August 26, 2014 10:02:30 AM UTC-7, Stefan Karpinski wrote:

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] 
> <javascript:>> 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
>> ​
>>
>
>  ​

Reply via email to