I can get you halfway there:
julia> Base.call{T<:Function}(fn::T, arg::Any) = begin println("I see:
($fn($arg))"); fn(arg) end
call (generic function with 1037 methods)
julia> Base.call{T<:Function}(fn::T, arg1::Any, arg2::Any) = begin
println("I see: ($fn($arg1,$arg2))"); fn(arg1,arg2) end
call (generic function with 1038 methods)
julia> call(exp,5.4)
I see: (exp(5.4))
221.40641620418717
julia> call(+,1,2)
I see: (+(1,2))
3
julia> exp(5.4)
221.40641620418717
julia> 1+2
3
On Monday, January 4, 2016 at 12:13:05 AM UTC-5, Julia Tylors wrote:
>
> How about we override
> Base.call{T}(::Type{T},args...) = ( mystuff; original Base.call; )
>
> Can i do something like this?
>
> Thanks
>
> On Sunday, January 3, 2016 at 6:58:49 PM UTC-8, Isaiah wrote:
>>
>> There is no AST-level distinction between a "constructor call" and a
>> "normal function call", see [1]. Look at the code in 'reflection.jl' to see
>> how to determine the applicable method for a given name (which may be a
>> constructor). If that doesn't help, it would be helpful to clarify the goal.
>>
>> For return statements, use `expand(a)` to convert the expression to goto
>> form, which should contain only explicit returns.
>>
>> [1] https://github.com/JuliaLang/julia/pull/8712
>>
>> On Sun, Jan 3, 2016 at 6:52 PM, Julia Tylors <[email protected]> wrote:
>>
>>> I am planning to detect the constructor calls and return statement of a
>>> function
>>>
>>>
>>> a = quote begin
>>> x = Foo(12)
>>> y = 5 + 6
>>> f(x.val,y)
>>> x.val * y
>>> end
>>>
>>> a is an Expr, in this expression , I would like to detect the
>>> constructor calls (Foo(12)( and distinguish them from normal function
>>> calls(fx.val,y).
>>> and i also want to identify the return statement, (x.val*y). How can i
>>> do it programmatically?
>>>
>>> Thanks
>>>
>>>
>>>
>>
>>