Hi Billou, thanks for letting me know about the |> esc part! I'll make a 
new topic to cover the macro part of this post.


On Friday, June 6, 2014 5:33:38 PM UTC+8, Billou Bielour wrote:
>
> For the macro problem, note that arguments of macro are expressions, or 
> Symbols:
>
> Just as functions map a tuple of argument values to a return value, macros 
>> map a tuple of argument expressions to a returned expression. They allow 
>> the programmer to arbitrarily transform the written code to a resulting 
>> expression, which then takes the place of the macro call in the final 
>> syntax tree. 
>>
>
> macro test(x); dump(x); end
>
> @test var
> Symbol var
>
> So you can do something like that:
>
> macro fetch(obj)
>     quote
>         local ic1eq = $obj.ic1eq
>         local ic2eq = $obj.ic2eq
>     end
> end
>
> This will not work however, because of hygiene:
>
> macroexpand (:(@fetch var))
>
> :(begin  # /opt/mandelbrot/session-manager/src/Worker.jl, line 3:
>         local #174#ic1eq = var.ic1eq # line 4:
>         local #175#ic2eq = var.ic2eq
>     end)
>
> You just need to escape your quote block:
>
> macro fetch(obj)
>     quote
>         local ic1eq = $obj.ic1eq
>         local ic2eq = $obj.ic2eq
>     end  |> esc
> end
>
> You can also look here for a similar question:
>
>
> https://groups.google.com/forum/#!searchin/julia-users/unpack/julia-users/IQS2mT1ITwU/gEyj6JNJsuAJ
>
>

Reply via email to