Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-26 Thread Fábio Cardeal
Alright! Here's a more complete and correct demonstration (And one I can fix without sending e-mails to everyone): https://gist.github.com/fcard/1bf78e9d4f6ea3be76518f6a0fbe0283 Sorry! Just don't wanna end the thread with wrong information, last one I promise! (I will make sure to have any

Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-24 Thread Fábio Cardeal
That explanation is a bit off actually, it's not that f1 can't optimize for t, it's that f1 has to do method lookup every time it's called. type X; x::Int end g1(x) = x.x+1 g2(x::X) = x.x+1 x = X(1) const y = X(1) @code_warntype g1(x) #... # begin #return

Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-24 Thread Fábio Cardeal
Actually the performance drop there is just because of the always looming threat of global var inefficience :P Because the var t is global, f1 can't optimize for its type. But f2 has a type declared on its argument, so it can. Remove the ::mytype on f2 or make t a const and you'll see no

Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-24 Thread Marius Millea
I think you are right btw, the compiler got rid of the wrapper function for the "+" call, since all I see above is Base.add_float. On Sun, Jul 24, 2016 at 4:55 PM, Marius Millea wrote: > Here's my very simple test case. I will also try on my actual code. > > using

Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-24 Thread Marius Millea
Here's my very simple test case. I will also try on my actual code. using SelfFunctions using TimeIt @selftype self type mytype x::Float64 end t = mytype(0) # Test @self'ed version: @self @inline function f1() 1+x end @timeit f1(t) println(@code_warntype(f1(t))) # 100 loops,

Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-24 Thread Fábio Cardeal
The compiler is pretty smart about removing these extra function calls, so I didn't get any extra overhead on my test cases. I went ahead and added `@inline` to the selfcall deckles. You can also do this: @self @inline function inc2() inc() inc() end Update from the gist and try

Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-24 Thread Marius Millea
Very nice! Didn't understand your hint earlier but now I do! My only problem with this solution is the (perhaps unavoidable) run-time overhead, since every single function call gets wrapped in one extra function call. With a very simple test function that just does some arithmetic, I'm seeing

[julia-users] Re: accessing an expression's global scope from macro

2016-07-23 Thread Fábio Cardeal
Hyy :) I made an implementation: https://gist.github.com/fcard/f356b01d5bb160dd486b9518ac292582 Julia 0.5 only. Enjoy...? Bye bye -- -

[julia-users] Re: accessing an expression's global scope from macro

2016-07-22 Thread Fábio Cardeal
Clearly the ingredient missing here is some evil type magic... Hint: immutable SelfFunction f::Function end selfcall(f::SelfFunction, t::MyType, args...) = f(t, args...) selfcall(f, t::MyType, args...) = f(args...) const inc2 = SelfFunction((t::MyType) -> begin selfcall(inc,

Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-22 Thread Mauro
On Fri, 2016-07-22 at 10:18, Marius Millea wrote: > Yea, thats a good point. Granted for my purpose I'm never going to be > redefining these types mid program. I suppose one might extend your @unpack > to work on an expression and do the substitution recursively like my

Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-22 Thread Marius Millea
Yea, thats a good point. Granted for my purpose I'm never going to be redefining these types mid program. I suppose one might extend your @unpack to work on an expression and do the substitution recursively like my thing does, then you could write, @unpack aa: a function(x,aa:A) sin(2pi/a*x)

Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-22 Thread Mauro
On Fri, 2016-07-22 at 01:02, Marius Millea wrote: >> FYI Mauro's package has something similar >> . >> > > Some interesting stuff in there, thanks! The problem with your `@self` and with Parameters.jl's

Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-21 Thread Yichao Yu
On Thu, Jul 21, 2016 at 7:02 PM, Marius Millea wrote: > > > On Thu, Jul 21, 2016 at 11:37 PM, Cedric St-Jean > wrote: >> >> Neat macro. >> >>> >>> For this though, my macro needs to somehow figure out that "inc" was also >>> defined with @self

Re: [julia-users] Re: accessing an expression's global scope from macro

2016-07-21 Thread Marius Millea
On Thu, Jul 21, 2016 at 11:37 PM, Cedric St-Jean wrote: > Neat macro. > > >> For this though, my macro needs to somehow figure out that "inc" was also >> defined with @self (since it shouldn't blindly add self as a first arg so >> other non-@self'ed function calls). Is

[julia-users] Re: accessing an expression's global scope from macro

2016-07-21 Thread Cedric St-Jean
Neat macro. > For this though, my macro needs to somehow figure out that "inc" was also > defined with @self (since it shouldn't blindly add self as a first arg so > other non-@self'ed function calls). Is this possible in Julia? > You could have a global Set that would contain the names of