Permalink
Browse files

Added support for @pattern f(::Int) etc

  • Loading branch information...
toivoh committed May 20, 2012
1 parent 667eaa4 commit a292de12a685764aec6a6e480153b6848fa1fd75
Showing with 12 additions and 4 deletions.
  1. +0 −1 pattern/core.jl
  2. +9 −3 pattern/recode.jl
  3. +3 −0 pattern/test/test_ambiguity_warning.jl
View
@@ -100,7 +100,6 @@ function show(io::IO, p::PVar)
end
end
-
## restrict the domain of a pattern
restrict( ::NonePattern, ::Domain) = nonematch
restrict(p::PVar, dom::Domain) = pvar(p.var, p.dom & dom)
View
@@ -49,9 +49,15 @@ function recode_pattern_ex(c::RPContext, ex::Expr)
head, args = ex.head, ex.args
nargs = length(args)
if head == doublecolon
- @expect nargs==2
- arg = recode_pattern_ex(c, args[1])
- return :( restrict(($arg), ($args[2])) )
+ @expect 1<=nargs<=2
+ if nargs == 1
+ var = quotevalue(pvar(gensym()))
+ dom = args[1]
+ else
+ var = recode_pattern_ex(c, args[1])
+ dom = args[2]
+ end
+ return :( restrict(($var), ($dom)) )
elseif contains([:call, :ref, :curly], head)
if (head==:call) && (args[1]==:staticvalue)
@expect nargs==2
@@ -50,3 +50,6 @@ load("pattern/pdispatch.jl")
@pattern f6(x,y,1,x,y) = 2
@pattern f6(x,y,x,y,1) = 3
+
+@pattern f7(::Int,::Any) = 2
+@pattern f7(x,::Int) = 3

0 comments on commit a292de1

Please sign in to comment.