Last active
August 29, 2015 13:57
-
-
Save carlobaldassi/9609450 to your computer and use it in GitHub Desktop.
Simplified invoke interface via macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro invoke(ex) | |
Meta.isexpr(ex, :call) || error("invoke macro syntax error") | |
isa(ex.args[1], Symbol) || error("invoke macro syntax error") | |
fname = ex.args[1] | |
types = [Meta.isexpr(a, :(::)) ? a.args[2] : Expr(:call, :typeof, a) for a in ex.args[2:end]] | |
args = [Meta.isexpr(a, :(::)) ? a.args[1] : a for a in ex.args[2:end]] | |
Expr(:call, :invoke, fname, Expr(:tuple, types...), args...) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> using Images | |
julia> b = randbool(5,5); | |
julia> i = Image(randbool(5,5)); | |
julia> i .* b | |
Binary Image with: | |
data: 5x5 BitArray{2} | |
properties: | |
limits: (false,true) | |
julia> @invoke i .* b | |
Binary Image with: | |
data: 5x5 BitArray{2} | |
properties: | |
limits: (false,true) | |
julia> @invoke i::AbstractArray .* b | |
5x5 Array{Bool,2}: | |
false true false false false | |
false true false true true | |
false true false true false | |
false false false false false | |
false true false true false | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment