-
-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Union problem in @capture
#40
Comments
Same goes for the other example... When I change the order in macro m2(ex)
if @capture(ex, (f_{T_}|f_)(args__) = body_)
@show f
@show T
@show args
@show body
end
return ex
end
@m2 f(x) = 5x
@m2 f{T}(x::T) = 3x
macro m3(ex)
if @capture(ex, (f_|f_{T_})(args__) = body_)
@show f
@show T
@show args
@show body
end
return ex
end
@m3 f(x) = 5x
@m3 f{T}(x::T) = 3x
macro m4(ex)
if @capture(ex, ((f_)(args__) = body_) | ((f_{T_})(args__) = body))
@show f
@show T
@show args
@show body
end
return ex
end
@m4 f(x) = 5x
@m4 f{T}(x::T) = 3x I cannot understand where I am doing a mistake. |
julia> @capture(:(f(x) = 5x), (f_{T_}|f_)(args__) = body_)
true
julia> @capture(:(f{T}(x) = 5x), (f_{T_}|f_)(args__) = body_)
true Are these definitely not working for you? |
Your examples do work. Now I get the point --- sorry! In the very first version, as you have pointed out, lack of parenthesis was causing the headache. Then, when I change the order of Thanks for the answer! |
I'm having a similar problem, but it shows up only if I restrict the type to match and use "|": Main> ex = @MacroTools.q ext_var1[2010:2049, (US, CHI)] = name1
:(ext_var1[2010:2049, (US, CHI)] = name1)
# Works without specifying Symbol type
Main> @capture(ex, extvar_ = rvname_)
true
# Captures a symbol
Main> rvname
:name1
# Works with Symbol type without "|"
Main> @capture(ex, extvar_ = rvname_Symbol)
true
# Works with "|" without Symbol type
Main> @capture(ex, (extvar_ = rvname_) | (extvar_ += rvname_))
true
# Fails with "|" and Symbol type
Main> @capture(ex, (extvar_ = rvname_Symbol) | (extvar_ += rvname_))
false
# Just for completeness:
Main> @capture(ex, (extvar_ = rvname_) | (extvar_ += rvname_Symbol))
true |
Closing, as the original question was answered. Filed new issue in #180 |
Hey! I was playing with the package and I spotted a problem while trying unions in
@capture
:Even though
m1
andm2
are copies fromREADME
, they don't work properly. I hope I am not missing some stupid mistake while trying.I'd appreciate if you could help. Thanks!
The text was updated successfully, but these errors were encountered: