Comments (6)
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.
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.
function bounding(::Type{>:UnitRange}, _union::(@FixT union UnitRange{T} UnitRange{T})) where T <: Integer
[...]
end
from fixargs.jl.
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.
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.
@xquoteT
is this (and probably the name should still be improved).
from fixargs.jl.
Related Issues (19)
- simplify type parameter corresponding to keyword arguments HOT 1
- positional placeholder ("holes") HOT 1
- reify function arguments on their own, e.g. `FrankenTuples` HOT 1
- TagBot trigger issue HOT 3
- nesting HOT 10
- Error message to suggest rewriting some syntax as a function call
- Do not use nothing for holes? HOT 29
- Mention related packages in README HOT 5
- `LazySets.jl` as case study HOT 1
- Connection to structural typing?
- Support or not for closures
- Related patterns HOT 4
- Broadcasting considerations HOT 2
- inference with nested lambdas
- Rename+export bind? HOT 4
- Version released to Pkg is old HOT 4
- Broadcast Functions not working
- Rename and register? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fixargs.jl.