Coder Social home page Coder Social logo

Comments (6)

jw3126 avatar jw3126 commented on May 17, 2024

It makes me sad, that we need to do this, but yeah I guess there is really a need for macros here. But do we really need two of them? Maybe the following would actually suffice?

@macroexpand @FixT f(::typeof(union), ::UnitRange{T}, ::UnitRange{T})
Fix{typeof(union), Tuple{Some{UnitRange{T}, UnitRange{T}}, Any}

from fixargs.jl.

goretkin avatar goretkin commented on May 17, 2024

I don't see where bounding comes into your example.

Anyway, like I said, it could be written with one macro. I just mentioned the decomposition because it seems like a worthwhile idea.

from fixargs.jl.

jw3126 avatar jw3126 commented on May 17, 2024
function bounding(::Type{>:UnitRange}, _union::(@FixT union UnitRange{T} UnitRange{T})) where T <: Integer
[...]
end

from fixargs.jl.

goretkin avatar goretkin commented on May 17, 2024

I assumed making this work with the type parameters would be problematic, but it looks like it is all fine!

e.g.

using Test: @test
macro Foo()
    return :(Complex{Int64})
end

macro Foo2(T)
    return :(Complex{$(esc(T))})
end

bar(x) = "fallback"
bar(x::(@Foo)) = "dispatch @Foo"
@test bar("") == "fallback"
@test bar(1+2im) == "dispatch @Foo"

bar2(x) = "fallback"
bar2(x::(@Foo2 Int64)) = "dispatch @Foo2 Int64"
bar2(x::(@Foo2 Float64)) = "dispatch @Foo2 Float64"
@test bar2(1 + 2im) == "dispatch @Foo2 Int64"
@test bar2(1 + 2.0im) == "dispatch @Foo2 Float64"

bar3(x) = "fallback"
bar3(x::(@Foo2 T)) where {T} = "dispatch @Foo2 T, where T = $T"
@test bar3(1 + 2im) == "dispatch @Foo2 T, where T = Int64"
@test bar3(1 + 2.0im) == "dispatch @Foo2 T, where T = Float64"

# double check
@show @macroexpand bar3(x::(@Foo2 T)) where {T}

from fixargs.jl.

goretkin avatar goretkin commented on May 17, 2024

I believe the definition of this macro should be based on this "rule", e.g.

typeof(FixArgs.@fix union([1], [2])) == FixArgs.@FixT union(::Vector{Int64}, ::Vector{Int64})

And it should probably also handle _. It should not handle keyword arguments.

I actually am glad there is a macro for this. It is nicely parallel.

foo(1 / 2) dispatches to foo(::Float64)
foo(@fix 1 / 2) dispatches to foo(::(@FixT ::Int64 / ::Int64))

I wonder if there are any suggestions to improve upon the FixT name.

from fixargs.jl.

goretkin avatar goretkin commented on May 17, 2024

@xquoteT is this (and probably the name should still be improved).

from fixargs.jl.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.