Re: [julia-users] nested macro with `let`

2016-05-05 Thread Yichao Yu
> Thank you for the careful explanation and code. It's exactly what I want. I > have a follow-up question: > > 1. I thought I'd make make a (personal) cosmetic modification to your > `value_dict`. > > macro value_dict(vars...) > rebindings = [:($(esc(var)) = value($(esc(var for var in vars]

Re: [julia-users] nested macro with `let`

2016-05-05 Thread Gustavo Goretkin
On Wednesday, May 4, 2016 at 1:05:07 PM UTC-4, Yichao Yu wrote: > Do not use `@eval` in macro, it happens in the wrong scope and in this > case, the wrong time. > > macro symbol_dict(symbols...) > :(Dict($([:($(QuoteNode(sym)) => $(esc(sym))) for sym in > symbols]...))) > end > > >

Re: [julia-users] nested macro with `let`

2016-05-04 Thread Yichao Yu
On Wed, May 4, 2016 at 12:09 PM, Gustavo Goretkin wrote: > I have this macro > > """given symbols, produce a dictionary of symbol=>value""" > macro symbol_dict(symbols...) > Dict([__x=>@eval($(__x)) for __x in symbols]) > end Do not use `@eval` in macro, it happens in the wrong scope and in t

[julia-users] nested macro with `let`

2016-05-04 Thread Gustavo Goretkin
I have this macro """given symbols, produce a dictionary of symbol=>value""" macro symbol_dict(symbols...) Dict([__x=>@eval($(__x)) for __x in symbols]) end that works like this julia> (x,y) = (30,50) (30,50) julia> @symbol_dict(x,y) Dict{Any,Any} with 2 entries: :y => 50 :x => 30 I hav