[julia-users] Re: eval in current scope

2016-09-27 Thread Fábio Cardeal
The lambda example works, but couldn't you do: function f(x) eval(:($x + 1)) end ? You can still do that in a macro: macro m() quote ex = :($x + 1) eval(ex) end end function f(x) @m end f(1) == 2 What would be a situation where this wouldn't work? Em terça-feira, 27 de

Re: [julia-users] Re: String printout in REPL vs println()

2016-09-26 Thread Fábio Cardeal
fault... > > Cheers! > > On 26 September 2016 at 15:17, Fábio Cardeal <fic...@gmail.com > > wrote: > >> "Any reason?" >> "None that I can think of..." >> "But you can use *show *if you need 'em" >> "You'll need to put t

[julia-users] Re: String printout in REPL vs println()

2016-09-26 Thread Fábio Cardeal
"Any reason?" "None that I can think of..." "But you can use *show *if you need 'em" "You'll need to put the newline yourself after it, tho." "there is also* display*, *@show*... Take a look here: http://docs.julialang.org/en/release-0.5/stdlib/io-network/#text-i-o; "" "Good luck!" if need 'em"

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] Effects of globals on dispatch + inlining

2016-07-26 Thread Fábio Cardeal
orough analysis of the problem space and it looks correct > to me. > > On Mon, Jul 25, 2016 at 7:46 PM, Fábio Cardeal <fic...@gmail.com > > wrote: > >> >> Hello . . . >> >> >> >> *BackstoryPreviously on julia-users...* >> Rece

[julia-users] Effects of globals on dispatch + inlining

2016-07-25 Thread Fábio Cardeal
Hello . . . *BackstoryPreviously on julia-users...* Recently on another thread I tried to explain to someone how globals were messing with type dispatch and inlining. They probably already knew but it was a just a `make-sure` quick explanation, then I tripped over it and now I want to make

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
gt; # 1000 loops, best of 3: 80.13 ns per loop >> # Variables: >> # #self#::#f2 >> # t::mytype >> # >> # Body: >> # begin >> # return >> (Base.box)(Base.Float64,(Base.add_float)((Base.box)(Float64,(Base.sitofp)(Float64,1)),(Core.getfiel

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

[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] Unions and TypeVar lower bounds

2016-01-04 Thread Fábio Cardeal
ant: > https://github.com/JuliaLang/julia/pull/11805 > > --Tim > > On Wednesday, December 30, 2015 09:50:27 AM Fábio Cardeal wrote: > > Given this: > > > > T = TypeVar(:T, Int, Any) > > > > > > I was wondering why while this happens: > &g

[julia-users] Unions and TypeVar lower bounds

2015-12-30 Thread Fábio Cardeal
Given this: T = TypeVar(:T, Int, Any) I was wondering why while this happens: julia> Int <: Integer true julia> Integer <: T true This also happens: julia> Int <: Union{Int,Char} true julia> Union{Int,Char} <: T false Is this intended behaviour and I am just not

[julia-users] Runtime inference of a function's return type

2015-06-23 Thread Fábio Cardeal
Is there a good way to find a function's return type with only the types of its arguments? I mean, I can do something like: codetyp(code) = code.args[3].typ function returntype(f::Function, types::Tuple) if isgeneric(f) mapreduce(codetyp, Union, code_typed(f, types))::Type

[julia-users] Re: Runtime inference of a function's return type

2015-06-23 Thread Fábio Cardeal
That's handy, thanks! And alright, I will keep that in mind.