-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Currently symbol literals in patterns don't really count as literals, but rather as a binding inside a QuoteNode
, which could be a gotcha. e.g.
@macromethod m(:sym1) 0
@macromethod m(:sym2) 1
# Intended: Different methods for specific symbols.
@m(:sym1) == 0
@m(:sym2) == 1
# Actual: Both are the same method, so second overwrites first.
@m(:sym1) == 1
@m(:sym2) == 1
# Since
@macromethod mtruth(:x) [x]
@mtruth(:a) == [:a]
# You have to:
@macromethod m1(:L{:sym1}) 0
@macromethod m1(:L{:sym2}) 1
# or:
@macromethod m2(:E{:(:sym1)}) 0
@macromethod m2(:E{:(:sym2)}) 1
@m1(:sym1) == @m2(:sym1) == 0
@m1(:sym2) == @m2(:sym2) == 1
This behaviour may be useful for capturing whole nested expressions (@mtruth(:(x+y)) == [:(x+y)]
) and changing it would make it inconsistent with capturing with nested expressions (@letds :(x+y) = :(:(1+2)) (x,y)
), but I don't know if these cases are common enough to keep this. Hmm.... Oh well, at least if Julia's 12139 happens this won't be a problem anymore!
I am gonna keep this one around until I do an overall update for Julia 0.5, but if you're a lost soul that somehow came across this and has opinions about it, feel free to share them!