That is beyond my comprehension. But I would like to try this.

Thank you both.

On Thu, Jan 15, 2015 at 5:00 PM, Mike Innes <[email protected]> wrote:

> quote...end is effectively the same as :(being ... end), that's all.
>
> I think you probably want something more like
>
> macro nb(f, args...)
>   :($f($(args...))) |> esc
> end
>
> since the function `f` should also be resolved at the call site.
>
> On 15 January 2015 at 03:39, yi lu <[email protected]> wrote:
>
>> I don't know why my previous version won't work,BUT
>>
>> ```
>> macro nb(f, args...)
>>            :($f($(arg...)))
>>        end
>> ```
>>
>>
>> will get the right result. What's the difference between `quote .. end`
>> and `:( .. )` then?
>>
>>
>> :P
>>
>> On Thu, Jan 15, 2015 at 11:06 AM, Isaiah Norton <[email protected]>
>> wrote:
>>
>>> julia> macro nb(f, args...)
>>>            arg1 = map(x->:($(esc(x))), args)
>>>            :($f($(arg1...)))
>>>        end
>>>
>>> julia> @nb print arr
>>> [0.0,0.020100000000000007, ...
>>>
>>> If you haven't used it already, I would suggest to look at macroexpand
>>> to see the expression resulting from each macro (for example, look at why
>>> the previous version didn't work).
>>>
>>> julia> macroexpand( :(@nb print arr) )
>>>
>>> On Wed, Jan 14, 2015 at 8:32 PM, yi lu <[email protected]>
>>> wrote:
>>>
>>>> Well, I don't get it very clearly. I learnt that 'esc' changes variable
>>>> names of a local variable in the macro. But I want to reference the global
>>>> variable out of the macro. I have little idea of Lisp macros, so I think I
>>>> still cannot handle this.
>>>> Would you please add more details?
>>>>
>>>> Yi
>>>>
>>>> On Wed, Jan 14, 2015 at 11:37 PM, Isaiah Norton <
>>>> [email protected]> wrote:
>>>>
>>>>> You need to use 'esc' -- see the hygiene part of the metaprog section
>>>>> in the manual.
>>>>> On Jan 14, 2015 8:56 AM, "yi lu" <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I am able to write a simple macro to drop brackets.
>>>>>> https://gist.github.com/eccstartup/36637d96355bd5ca8188
>>>>>>
>>>>>> But there is some problem with this.
>>>>>>
>>>>>> You can see the @nobrace macro that drop brackets of functions.
>>>>>> For example:
>>>>>> ```
>>>>>> @nobrace map (x->x^2-1) 1:0.01:2
>>>>>> ```
>>>>>> get a list of Float numbers. This is fine.
>>>>>>
>>>>>> However, in the macro, we cannot see global variables.
>>>>>> For example:
>>>>>> ```
>>>>>> arr = @nobrace map (x->x^2-1) 1:0.01:2
>>>>>> print(arr)
>>>>>> ```
>>>>>> will print the "arr" list, but
>>>>>> ```
>>>>>> arr = @nobrace map (x->x^2-1) 1:0.01:2
>>>>>> @nobrace print arr
>>>>>> ```
>>>>>> will report "arr not found".
>>>>>>
>>>>>> Is there a remedy?
>>>>>>
>>>>>>
>>>>>> Yours,
>>>>>> Yi
>>>>>>
>>>>>
>>>>
>>>
>>
>

Reply via email to