On Thu, Aug 11, 2016 at 6:40 AM, Andrei Zh <faithlessfri...@gmail.com>
wrote:

> One more question related to the topic. I try to get function body
> expression in Julia 0.5 using:
>
> lambda = methods(func, types).ms[1].lambda_template
> Base.uncompressed_ast(lambda)
>
> However this gives an expression with argument names replaced by
> `SlotNumber` (e.g. `_2`). Is there a way to get function expression with
> actual variable names or a recommended way to convert `SlotNumbers` to it?
> So far I've only found this piece of code
> <https://github.com/JuliaDiff/ReverseDiffSource.jl/blob/master/src/frdiff.jl#L63-L76>
> in ReverseDiffSource.jl, but the package is currently broken under Julia
> 0.5, so I suppose there might be more stable way to do it.
>

`slotnames` of LambdaInfo should have what you want.
Do note that the name is not unique.


>
>
> On Monday, August 8, 2016 at 10:39:34 PM UTC+3, Andrei Zh wrote:
>>
>> Thanks, this makes sense. Just for clarification:
>>
>>
>>> It strongly depend on what you want to do and whether you care about
>>> what they represent.
>>>
>>
>> I want to apply transformations (mostly) to algebraic expressions and
>> function calls in order to simplify them, replace argument names, find
>> derivatives, etc. Thus I don't really care about the difference between
>> GlobalRef and dot notation as long as they contain the same amount of
>> information and I can evaluate them to actual function objects. But since
>> there's a choice between 2 options I was trying to understand which one is
>> more suitable for me and whether I can cast one to another (again, in the
>> context of my simple transformations).
>>
>> Now based on what you've told about optimization and
>> `Base.uncompressed_ast()` I believe these 2 options - GloablRef and dot
>> notation - are interchangeable for my use case.
>>
>>
>>> The devdoc should have fairly complete description of what these nodes
>>> are.
>>>
>>
>> What they are - yes, but not when to use which one. Anyway, I didn't
>> intend to abuse anyone, just tried to get my head around AST internals.
>>
>>
>>
>>>
>>>
>>>>
>>>>
>>>>
>>>> On Monday, August 8, 2016 at 1:55:51 AM UTC+3, Yichao Yu wrote:
>>>>>
>>>>>
>>>>>
>>>>> On Mon, Aug 8, 2016 at 3:57 AM, Andrei Zh <faithle...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> While parsing Julia expressions, I noticed that sometimes calls to
>>>>>>
>>>>>
>>>>> This shouldn't happen.
>>>>>
>>>>>
>>>>>> global functions resolve to `GloablRef` and sometimes to
>>>>>>
>>>>>
>>>>> and GlobalRef should only happen during lowering.
>>>>>
>>>>>
>>>>>> getfield(Module, func). Could somebody please clarify:
>>>>>>
>>>>>> 1. Why do we need both?
>>>>>>
>>>>>
>>>>> GlobalRef is essentially an optimization. It's more restricted and
>>>>> easier to interpret/codegen and is emitted by lowering/type inference when
>>>>> it is legal to do so.
>>>>>
>>>>>
>>>>>> 2. Is it safe to replace one by the other (assuming only modules and
>>>>>> functions are involved)?
>>>>>>
>>>>>
>>>>> Not always. There are certainly cases where a GlobalRef currently
>>>>> can't be used (method definition for example) I'm not sure if there's 
>>>>> cases
>>>>> the other way around.
>>>>>
>>>>>
>>>

Reply via email to