I just want to make fun with Julia macro ...

'@awhen' will set the first `expr` as  `it` in a let block.
and then use `it` in remain arguments.
eg: `@awhen([1,2,3,4], it[1], it[2])`



Johan Sigfrids於 2015年3月16日星期一 UTC+8下午5時34分18秒寫道:
>
> What is that macro supposed to do?
>
> On Monday, March 16, 2015 at 7:12:14 AM UTC+2, Miao Yang wrote:
>>
>> macro awhen(expr, body...)
>>     esc(quote
>>         let it = $(expr)
>>           if it != nothing
>>             $(body...)
>>           end
>>         end
>>    end)
>> end
>>
>> julia> @awhen([1, 2, 3], it[2]) # workds fine
>> 2
>> julia> @awhen(nothing, it[2]) # workds fine
>>
>> julia> @awhen([1, 2, 3], x = 1, it[x]) # :(, failed
>>
>> ERROR: unsupported or misplaced expression kw
>>
>>
>> julia> macroexpand(:@awhen([1,2,3], x = 1, it[x]))
>> quote  # none, line 3:
>>     let it = [1,2,3] # line 4:
>>         if it != nothing # line 5:
>>             x=1
>>             it[x]
>>         end
>>     end
>> end
>>
>>
>> Have no idea how to let this worked...
>> Please help me, thanks.
>>
>

Reply via email to