macro unpack(p)
  Expr(:block, [:($(n[i]) = $p[$i]) for i = 1:length(n)]...) |> esc
end

Ok, that should work better. To avoid the hygiene pass you can wrap
everything in esc; for example

macro unpack()
  quote
    a = p[1]
    b = p[2]
  end |> esc
end


On 14 March 2014 18:30, John Myles White <[email protected]> wrote:

> Stupid seems a little harsh. Maybe just a bit vague. :)
>
>  -- John
>
> On Mar 14, 2014, at 11:27 AM, Yuuki Soho <[email protected]> wrote:
>
> That was a slightly stupid question John, I should have thought about it 2
> minutes:)
> I was hopping to do something like that, but it doesn't work because of
> the hygiene I guess.
>
> macro unpack()
>
> quote
>
> a = p[1]
>
> b = p[2]
>
> end
>
> end
>
> macroexpand(:(@unpack))
> #184#a = p[1] # line 1: #185#b = p[2]
>
> This is what I get with yours Mike:
>
> @unpack [1,2,3]
> 3-element Array{Expr,1}: :(a = [1,2,3][1]) :(b = [1,2,3][2]) :(c =
> [1,2,3][3])
>
> Thanks for the answers!
>
>
>

Reply via email to