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
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
"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"
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
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
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
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
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
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
Hyy :)
I made an implementation:
https://gist.github.com/fcard/f356b01d5bb160dd486b9518ac292582
Julia 0.5 only. Enjoy...? Bye bye
--
-
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,
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
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
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
That's handy, thanks! And alright, I will keep that in mind.
15 matches
Mail list logo