Permalink
Browse files

Moved old stuff to attic and moved down pattern/test, small bugfix.

  • Loading branch information...
1 parent 1c87589 commit 4dfc85f9e8c11b9c719e2f92f5b1000a248a2448 @toivoh committed May 20, 2012
Showing with 448 additions and 448 deletions.
  1. 0 { → attic/first}/ifmatch.jl
  2. 0 { → attic/first}/meta.jl
  3. 0 { → attic/first}/patterns.jl
  4. 0 { → attic/first}/pdispatch.jl
  5. 0 { → attic/first}/pmatch.jl
  6. +13 −23 {pattern → attic/first}/test/test_ambiguity_warning.jl
  7. +35 −0 attic/first/test/test_code_pmatch.jl
  8. +16 −0 attic/first/test/test_ifmatch.jl
  9. 0 { → attic/first}/test/test_isatomtype.jl
  10. +3 −22 {pattern → attic/first}/test/test_pdisp.jl
  11. +55 −0 attic/first/test/test_unify.jl
  12. +41 −0 attic/first/test/test_unify_vectors.jl
  13. 0 {dev → attic/first}/utils/req.jl
  14. 0 { → attic/first}/utils/utils.jl
  15. 0 {dev → attic/second}/ifmatch.jl
  16. 0 {dev → attic/second}/patterns.jl
  17. 0 {dev → attic/second}/pdispatch.jl
  18. 0 {dev → attic/second}/pmatch.jl
  19. 0 {dev → attic/second}/recode.jl
  20. 0 {dev → attic/second}/test/test_ambiguity_warning.jl
  21. 0 {dev → attic/second}/test/test_code_pmatch.jl
  22. 0 {dev → attic/second}/test/test_ifmatch.jl
  23. 0 {dev → attic/second}/test/test_pdisp.jl
  24. 0 {dev → attic/second}/test/test_recode.jl
  25. 0 {dev → attic/second}/test/test_unify.jl
  26. 0 {dev → attic/second}/test/test_unify_vectors.jl
  27. 0 { → attic/second}/utils/req.jl
  28. 0 {dev → attic/second}/utils/utils.jl
  29. +1 −1 pattern/composites.jl
  30. +0 −49 pattern/test/test_code_pmatch.jl
  31. +0 −53 pattern/test/test_ifmatch.jl
  32. +0 −96 pattern/test/test_unify.jl
  33. +0 −79 pattern/test/test_unify_vectors.jl
  34. +23 −13 test/test_ambiguity_warning.jl
  35. 0 {pattern → }/test/test_array.jl
  36. +32 −18 test/test_code_pmatch.jl
  37. +46 −9 test/test_ifmatch.jl
  38. +22 −3 test/test_pdisp.jl
  39. 0 {pattern → }/test/test_recode.jl
  40. +92 −51 test/test_unify.jl
  41. +69 −31 test/test_unify_vectors.jl
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,7 +1,6 @@
-
-load("pattern/pdispatch.jl")
-
+load("utils/req.jl")
+load("pdispatch.jl")
## should work ##
@@ -11,18 +10,12 @@ load("pattern/pdispatch.jl")
@pattern r(x,y::Int) = 3
# no finite unification ==> ok
-@pattern r2(x,(1,x)) = 2
+@pattern r2(x,{1,x}) = 2
@pattern r2(y,y) = 3
-@pattern r3((x,y),(z,w)) = 1
-@pattern r3(x,(y,z)) = 2
-@pattern r3((x,y),z) = 3
-
-@pattern r4(1)=1
-@pattern r4(x)=x
-
-@pattern r5(x)=x
-@pattern r5(1)=1
+@pattern r3({x,y},{z,w}) = 1
+@pattern r3(x,{y,z}) = 2
+@pattern r3({x,y},z) = 3
@pattern r4(1,x,y::Int) = 2
@pattern r4(2,x::Int,y) = 3
@@ -32,24 +25,21 @@ load("pattern/pdispatch.jl")
## should warn ##
-# should warn about f1(::Int,::Int)
+# should warn about g(::Int,::Int)
@pattern f1(x::Int,y) = 2
@pattern f1(x,y::Int) = 3
-@pattern f2((1,x),y) = 2
-@pattern f2(z,(2,w)) = 3
+@pattern f2({1,x},y) = 2
+@pattern f2(z,{2,w}) = 3
@pattern f3(x::Union(Int,String)) = 2
@pattern f3(x::Real) = 3
@pattern f4(x,2) = x
@pattern f4(1,y) = y
-@pattern f5(y,(x,x),(y,y)) = 2
-@pattern f5(y,y,z) = 3
-
-@pattern f6(x,y,1,x,y) = 2
-@pattern f6(x,y,x,y,1) = 3
+@pattern f6(y,{x,x},{y,y}) = 2
+@pattern f6(y,y,z) = 3
-@pattern f7(::Int,::Any) = 2
-@pattern f7(x,::Int) = 3
+@pattern f7(x,y,1,x,y) = 2
+@pattern f7(x,y,x,y,1) = 3
@@ -0,0 +1,35 @@
+
+load("utils/req.jl")
+req("prettyshow/prettyshow.jl")
+
+load("pmatch.jl")
+
+
+function show_code_pmatch(p,vars::PVar...)
+ println()
+ println("pattern = ", p)
+
+ d = Dict()
+ for var in vars
+ d[var.name] = var
+ end
+
+ c = PMContext(d)
+ code_pmatch(c, p,:x)
+ println("vars = ", c.vars)
+# println("code:")
+# foreach(x->println("\t", x), c.code)
+ pprintln(expr(:block, c.code))
+end
+
+@pvar X, Xi::Int
+
+show_code_pmatch(1)
+show_code_pmatch(X, X)
+show_code_pmatch(Xi, Xi)
+show_code_pmatch((1,X), X)
+show_code_pmatch((X,X), X)
+
+
+c = RPContext()
+@showln pattern = recode_pattern(c, :(X,1,value(X),X))
@@ -0,0 +1,16 @@
+
+load("ifmatch.jl")
+
+
+@ifmatch let (X,1)=(2,1)
+ println("X = ", X)
+end
+
+println()
+for k=1:4
+ if !@ifmatch let (X,value(k))=(1,2)
+ println("k=$k: X=$X")
+ end
+ println("k=",k)
+ end
+end
File renamed without changes.
@@ -1,6 +1,7 @@
-
-load("pattern/pdispatch.jl")
+load("utils/req.jl")
+load("pdispatch.jl")
+req("prettyshow/prettyshow.jl")
mtable = PatternMethodTable(:f)
add(mtable, (@patmethod f(1) = 42))
@@ -23,27 +24,7 @@ println()
@show ff(2)
@show ff(3)
-@pattern f2({x,y}) = 1
-@pattern f2(x) = 2
-
-println()
-@show f2(1)
-@show f2({1})
-@show f2({1,2})
-@show f2((1,2))
-@show f2({1,2,3})
-
-@pattern f3((x,y)) = 1
-@pattern f3(x) = 2
-println()
-@show f3(1)
-@show f3((1))
-@show f3((1,2))
-@show f3({1,2})
-@show f3((1,2,3))
-
-println()
println("(g=1;@pattern g(x)=1) throws: ", @assert_fails begin
g = 1
@pattern g(x)=1
@@ -0,0 +1,55 @@
+
+load("pmatch.jl")
+load("utils/req.jl")
+req("utils/utils.jl")
+
+let
+ @show @pvar X, Y
+
+ @show X
+ @show pvar(:Z, Int)
+ @show pvar(:Z, Any)
+ @show pvar(:Z, None)
+
+ println()
+ @show restr(Int, 1)
+ @show restr(Float, 1)
+
+ println()
+ @symshow unify(X, 3)
+ @symshowln unify(X, (4, "hej"))
+
+ println()
+ @showln unify(match(Any), match(Any))
+ @symshowln unify(match(Any), 1)
+ @symshowln unify(match(Real), 1)
+ @symshowln unify(match(Int), 1)
+ @symshowln unify(match(Float), 1)
+ @symshowln unify(nonematch, 1)
+
+ println()
+ @showln unify(match(Real), match(Real))
+ @symshowln unify(match(Real), match(Int))
+ @symshowln unify(match(Float), match(Int))
+
+ @pvar Xr::Real, Xi::Int, Xf::Float
+
+ println()
+ @symshowln unify(Xr, Xi)
+ @symshow unify(Xi, Xf)
+
+ println()
+ @symshowln unify(Xi, 2)
+ @symshowln unify(Xr, 2.0)
+ @symshowln unify(Xi, 2.0)
+ @symshowln unify(Xi, 2.5)
+
+ println()
+ @symshowln unify(match(Any), 1)
+ @symshowln unify(match(Any), X)
+ @symshowln unify(match(Any), Xi)
+
+ println()
+ @show unify(X, X)
+ @show unify(X, Y)
+end
@@ -0,0 +1,41 @@
+
+load("pmatch.jl")
+load("utils/req.jl")
+req("utils/utils.jl")
+
+let
+ @pvar X, Y, Z
+
+ @symshowln unify(X, {1,2})
+ @symshowln unify({X,2}, {1,2})
+ @symshowln unify({X,1}, {1,2})
+ @symshowln unify({1,X}, {1,2})
+ @symshowln unify({1,X}, {Y,2})
+ @symshowln unify({1,X}, {1,2,3})
+ @symshowln unify({1,X,Y}, {1,2,3})
+ @symshowln unify({1,X}, {1,{2,3}})
+
+ println()
+ @symshowln unify({1,X}, {X,Y})
+ @symshowln unify({1,X,Y}, {X,Y,Z})
+ @symshowln unify({1,X,Y}, {X,Y,1})
+ @symshowln unify({1,X,Y}, {X,Y,2})
+ @symshowln unify({1,Y,X}, {X,Z,Y})
+ @symshowln unify(X, {1,X})
+
+ println()
+ @pvar Xi::Int, Xa::Array, Xv::Vector, Xm::Matrix
+ @symshowln unify(Xi, {1,2})
+ @symshowln unify(Xa, {1,2})
+ @symshowln unify(Xv, {1,2})
+ @symshowln unify(Xm, {1,2})
+
+ println()
+ @pvar Xai::Array{Int}
+ @symshowln unify(Xai, {1,2})
+ @symshowln unify(Xai, [1,2])
+ @symshowln unify(Xa, [1,2,X])
+
+ # consider: Should this work? And force X to be an Int.
+ @symshowln unify(Xai, [1,2,X])
+end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -41,7 +41,7 @@ show_unpatterned(io::IO,p::ArrayPat{1})= show_unpatterned_list(io,"{",p.ps,"}")
function show_unpatterned_list(io::IO, open::String, ps, close::String)
print(io,open)
- n = length(p.ps)
+ n = length(ps)
for k=1:n
show_unpatterned(io, ps[k])
print(io, ",")
@@ -1,49 +0,0 @@
-
-load("pattern/req.jl")
-req("pattern/core.jl")
-req("pattern/composites.jl")
-req("pattern/recode.jl")
-load("pattern/pmatch.jl")
-req("prettyshow/prettyshow.jl")
-
-@showln @assert_fails code_pmatch(nonematch, :arg)
-
-X = pvar(:X)
-
-pprintln()
-@pshowln code_pmatch(X, :arg)
-pprintln()
-@pshowln code_pmatch(1, :arg)
-
-#pprintln(code_pmatch(DomPattern(pvar(:x), domain(Int)), :arg))
-
-println()
-@pshowln code_pmatch((1, X), :args)
-# println()
-# @pshowln code_pmatch({1, X}, :args)
-
-
-function show_code_pmatch(p)
- println()
- println("pattern = ", p)
-
- c = PMContext()
- code_pmatch(c, aspattern(p),:x)
- println("vars = ", c.assigned_vars)
-# println("code:")
-# foreach(x->println("\t", x), c.code)
- pprintln(expr(:block, c.code))
-end
-
-#@pvar X, Xi::Int
-X, Xi = pvar(:X), pvar(:Xi, Int)
-
-show_code_pmatch(1)
-show_code_pmatch(X)
-show_code_pmatch(Xi)
-show_code_pmatch((1,X))
-show_code_pmatch((X,X))
-show_code_pmatch({1,X})
-show_code_pmatch({X,X})
-
-
@@ -1,53 +0,0 @@
-
-load("pattern/req.jl")
-req("pattern/core.jl")
-req("pattern/composites.jl")
-load("pattern/ifmatch.jl")
-
-y=5
-@ifmatch let x=1
- global y=x
- println("x = ", x)
-end
-assert y==1
-
-println()
-for k=1:5
- print("k = ", k)
- matched = @ifmatch let 2=k
- @assert k==2
- print(", == 2!")
- end
- @assert matched == (k==2)
- println()
-end
-
-println()
-@ifmatch let (x,y,3)=(1,2,3)
- @show x,y
-end
-@ifmatch let {x,y,4}={2,3,4}
- @show x,y
-end
-
-# no-matches:
-@ifmatch let {x,y,3}=(6,5,3)
- @show x,y
-end
-@ifmatch let (x,y,3)=(6,5,4)
- @show x,y
-end
-@ifmatch let (x,y,3)=(6,5)
- @show x,y
-end
-
-println()
-@ifmatch let x::Int=3
- @show x
-end
-@ifmatch let x::Int=3.0
- @show x
-end
-@ifmatch let x::Int="nnkj"
- @show x
-end
Oops, something went wrong.

0 comments on commit 4dfc85f

Please sign in to comment.