Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 4dfc85f9e8c11b9c719e2f92f5b1000a248a2448 1 parent 1c87589
@toivoh authored
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  { → 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  {dev → 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
View
0  ifmatch.jl → attic/first/ifmatch.jl
File renamed without changes
View
0  meta.jl → attic/first/meta.jl
File renamed without changes
View
0  patterns.jl → attic/first/patterns.jl
File renamed without changes
View
0  pdispatch.jl → attic/first/pdispatch.jl
File renamed without changes
View
0  pmatch.jl → attic/first/pmatch.jl
File renamed without changes
View
36 pattern/test/test_ambiguity_warning.jl → attic/first/test/test_ambiguity_warning.jl
@@ -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,12 +25,12 @@ 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
@@ -45,11 +38,8 @@ load("pattern/pdispatch.jl")
@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
View
35 attic/first/test/test_code_pmatch.jl
@@ -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))
View
16 attic/first/test/test_ifmatch.jl
@@ -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
View
0  test/test_isatomtype.jl → attic/first/test/test_isatomtype.jl
File renamed without changes
View
25 pattern/test/test_pdisp.jl → attic/first/test/test_pdisp.jl
@@ -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
View
55 attic/first/test/test_unify.jl
@@ -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
View
41 attic/first/test/test_unify_vectors.jl
@@ -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
View
0  utils/req.jl → attic/first/utils/req.jl
File renamed without changes
View
0  utils/utils.jl → attic/first/utils/utils.jl
File renamed without changes
View
0  dev/ifmatch.jl → attic/second/ifmatch.jl
File renamed without changes
View
0  dev/patterns.jl → attic/second/patterns.jl
File renamed without changes
View
0  dev/pdispatch.jl → attic/second/pdispatch.jl
File renamed without changes
View
0  dev/pmatch.jl → attic/second/pmatch.jl
File renamed without changes
View
0  dev/recode.jl → attic/second/recode.jl
File renamed without changes
View
0  dev/test/test_ambiguity_warning.jl → attic/second/test/test_ambiguity_warning.jl
File renamed without changes
View
0  dev/test/test_code_pmatch.jl → attic/second/test/test_code_pmatch.jl
File renamed without changes
View
0  dev/test/test_ifmatch.jl → attic/second/test/test_ifmatch.jl
File renamed without changes
View
0  dev/test/test_pdisp.jl → attic/second/test/test_pdisp.jl
File renamed without changes
View
0  dev/test/test_recode.jl → attic/second/test/test_recode.jl
File renamed without changes
View
0  dev/test/test_unify.jl → attic/second/test/test_unify.jl
File renamed without changes
View
0  dev/test/test_unify_vectors.jl → attic/second/test/test_unify_vectors.jl
File renamed without changes
View
0  dev/utils/req.jl → attic/second/utils/req.jl
File renamed without changes
View
0  dev/utils/utils.jl → attic/second/utils/utils.jl
File renamed without changes
View
2  pattern/composites.jl
@@ -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, ",")
View
49 pattern/test/test_code_pmatch.jl
@@ -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})
-
-
View
53 pattern/test/test_ifmatch.jl
@@ -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
View
96 pattern/test/test_unify.jl
@@ -1,96 +0,0 @@
-
-load("pattern/req.jl")
-req("pattern/core.jl")
-req("pattern/composites.jl")
-load("pattern/pmatch.jl")
-
-uni(x, y) = unify(aspattern(x), aspattern(y))
-pat_gt(x, y) = pattern_gt(aspattern(x), aspattern(y))
-pat_eq(x, y) = pattern_eq(aspattern(x), aspattern(y))
-
-@symshowln uni(1, nonematch)
-@symshowln uni(nonematch, nonematch)
-
-X, Y, Z = map(pvar, (:X, :Y, :Z))
-
-@symshowln uni(X, nonematch)
-@symshowln uni(X, 1)
-@symshowln uni(X, X)
-@symshowln uni(X, Y)
-
-@assert pat_gt(1, nonematch)
-@assert pat_eq(nonematch, nonematch)
-
-@assert pat_gt(X, nonematch)
-@assert pat_gt(X, 1)
-@assert pat_eq(X, X)
-@assert pat_eq(X, Y)
-
-@assert uni(1, nonematch)[1] == nonematch
-@assert uni(1, 1)[1] == Atom(1)
-@assert uni(1, 2)[1] == nonematch
-@assert uni(X, nonematch)[1] == nonematch
-@assert uni(X, 3)[1] == Atom(3)
-@assert uni(X, X)[1] == X
-@assert uni(X, Y)[1] == Y
-@assert uni(Y, X)[1] == X
-
-println()
-@symshowln uni(X, (1,2))
-@symshowln uni((X,), (1,2))
-@symshowln uni((X,Y), (1,2))
-@symshowln uni((1,Y), (1,2))
-@symshowln uni((1,Y), (X,2))
-@symshowln uni((1,X,Y), (X,Y,Z))
-@symshowln uni((1,Y,X), (X,Z,Y))
-@symshowln uni((1,X,Y), (X,Y,2))
-@symshowln uni((1,nonematch),(1,2))
-@symshowln uni((X,Y),((Y,Y),(Z,Z)))
-
-@assert uni(X, (1,2))[1] == aspattern((1,2))
-@assert uni((X,), (1,2))[1] == nonematch
-@assert uni((X,Y), (1,2))[1] == aspattern((1,2))
-@assert uni((1,Y), (1,2))[1] == aspattern((1,2))
-@assert uni((1,Y), (X,2))[1] == aspattern((1,2))
-@assert uni((1,X,Y), (X,Y,Z))[1] == aspattern((1,1,1))
-@assert uni((1,Y,X), (X,Z,Y))[1] == aspattern((1,1,1))
-@assert uni((1,X,Y), (X,Y,2))[1] == nonematch
-@assert uni((1,nonematch),(1,2))[1] == nonematch
-@assert uni((X,Y),((Y,Y),(Z,Z)))[1] == aspattern((((Z,Z),(Z,Z)),(Z,Z)))
-
-
-# println()
-# @showln uni(match(Any), match(Any))
-# @symshowln uni(match(Any), 1)
-# @symshowln uni(match(Real), 1)
-# @symshowln uni(match(Int), 1)
-# @symshowln uni(match(Float), 1)
-# @symshowln uni(nonematch, 1)
-
-# println()
-# @showln uni(match(Real), match(Real))
-# @symshowln uni(match(Real), match(Int))
-# @symshowln uni(match(Float), match(Int))
-
-#@pvar Xr::Real, Xi::Int, Xf::Float
-Xr, Xi, Xf = pvar(:Xr,Real), pvar(:Xi,Int), pvar(:Xf,Float)
-
-println()
-@symshowln uni(Xr, Xi)
-@symshow uni(Xi, Xf)
-
-println()
-@symshowln uni(Xi, 2)
-@symshowln uni(Xr, 2.0)
-@symshowln uni(Xi, 2.0)
-@symshowln uni(Xi, 2.5)
-
-# println()
-# @symshowln uni(match(Any), 1)
-# @symshowln uni(match(Any), X)
-# @symshowln uni(match(Any), Xi)
-
-
-println()
-@show z, s = uni(X,1)
-@show s[aspattern(((X,2),(X,3)))]
View
79 pattern/test/test_unify_vectors.jl
@@ -1,79 +0,0 @@
-
-load("pattern/req.jl")
-req("pattern/core.jl")
-req("pattern/composites.jl")
-load("pattern/pmatch.jl")
-
-
-let
- uni(x, y) = unify(aspattern(x), aspattern(y))
-
- X, Y, Z = map(pvar, (:X, :Y, :Z))
-
- @symshowln uni(X, {1,2})
- @symshowln uni({X,2}, {1,2})
- @symshowln uni({X,1}, {1,2})
- @symshowln uni({1,X}, {1,2})
- @symshowln uni({1,X}, {Y,2})
- @symshowln uni({1,X}, {1,2,3})
- @symshowln uni({1,X,Y}, {1,2,3})
- @symshowln uni({1,X}, {1,{2,3}})
-
- println()
- @symshowln uni({1,X}, {X,Y})
- @symshowln uni({1,X,Y}, {X,Y,Z})
- @symshowln uni({1,X,Y}, {X,Y,1})
- @symshowln uni({1,X,Y}, {X,Y,2})
- @symshowln uni({1,Y,X}, {X,Z,Y})
- @symshowln uni(X, {1,X})
-
-# println()
-# @pvar Xi::Int, Xa::Array, Xv::Vector, Xm::Matrix
-# @symshowln uni(Xi, {1,2})
-# @symshowln uni(Xa, {1,2})
-# @symshowln uni(Xv, {1,2})
-# @symshowln uni(Xm, {1,2})
-
-# println()
-# @pvar Xai::Array{Int}
-# @symshowln uni(Xai, {1,2})
-# @symshowln uni(Xai, [1,2])
-# @symshowln uni(Xa, [1,2,X])
-
-# # consider: Should this work? And force X to be an Int.
-# @symshowln uni(Xai, [1,2,X])
-
-
-# @symshowln uni(X, (1,2))
-# @symshowln uni((X,2), (1,2))
-# @symshowln uni((X,1), (1,2))
-# @symshowln uni((1,X), (1,2))
-# @symshowln uni((1,X), (Y,2))
-# @symshowln uni((1,X), (1,2,3))
-# @symshowln uni((1,X,Y), (1,2,3))
-# @symshowln uni((1,X), (1,(2,3)))
-
-# println()
-# @symshowln uni((1,X), (X,Y))
-# @symshowln uni((1,X,Y), (X,Y,Z))
-# @symshowln uni((1,X,Y), (X,Y,1))
-# @symshowln uni((1,X,Y), (X,Y,2))
-# @symshowln uni((1,Y,X), (X,Z,Y))
-# @symshowln uni(X, (1,X))
-
-# # println()
-# # @pvar Xi::Int, Xa::Array, Xv::Vector, Xm::Matrix
-# # @symshowln uni(Xi, (1,2))
-# # @symshowln uni(Xa, (1,2))
-# # @symshowln uni(Xv, (1,2))
-# # @symshowln uni(Xm, (1,2))
-
-# # println()
-# # @pvar Xai::Array(Int)
-# # @symshowln uni(Xai, (1,2))
-# # @symshowln uni(Xai, [1,2])
-# # @symshowln uni(Xa, [1,2,X])
-
-# # # consider: Should this work? And force X to be an Int.
-# # @symshowln uni(Xai, [1,2,X])
-end
View
36 test/test_ambiguity_warning.jl
@@ -1,6 +1,7 @@
-load("utils/req.jl")
-load("pdispatch.jl")
+
+load("pattern/pdispatch.jl")
+
## should work ##
@@ -10,12 +11,18 @@ load("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 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 r4(1,x,y::Int) = 2
@pattern r4(2,x::Int,y) = 3
@@ -25,12 +32,12 @@ load("pdispatch.jl")
## should warn ##
-# should warn about g(::Int,::Int)
+# should warn about f1(::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
@@ -38,8 +45,11 @@ load("pdispatch.jl")
@pattern f4(x,2) = x
@pattern f4(1,y) = y
-@pattern f6(y,{x,x},{y,y}) = 2
-@pattern f6(y,y,z) = 3
+@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 f7(x,y,1,x,y) = 2
-@pattern f7(x,y,x,y,1) = 3
+@pattern f7(::Int,::Any) = 2
+@pattern f7(x,::Int) = 3
View
0  pattern/test/test_array.jl → test/test_array.jl
File renamed without changes
View
50 test/test_code_pmatch.jl
@@ -1,35 +1,49 @@
-load("utils/req.jl")
+load("pattern/req.jl")
+req("pattern/core.jl")
+req("pattern/composites.jl")
+req("pattern/recode.jl")
+load("pattern/pmatch.jl")
req("prettyshow/prettyshow.jl")
-load("pmatch.jl")
+@showln @assert_fails code_pmatch(nonematch, :arg)
+X = pvar(:X)
-function show_code_pmatch(p,vars::PVar...)
+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)
- d = Dict()
- for var in vars
- d[var.name] = var
- end
-
- c = PMContext(d)
- code_pmatch(c, p,:x)
- println("vars = ", c.vars)
+ 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
+#@pvar X, Xi::Int
+X, Xi = pvar(:X), pvar(: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)
+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})
-c = RPContext()
-@showln pattern = recode_pattern(c, :(X,1,value(X),X))
View
55 test/test_ifmatch.jl
@@ -1,16 +1,53 @@
-load("ifmatch.jl")
+load("pattern/req.jl")
+req("pattern/core.jl")
+req("pattern/composites.jl")
+load("pattern/ifmatch.jl")
-
-@ifmatch let (X,1)=(2,1)
- println("X = ", X)
+y=5
+@ifmatch let x=1
+ global y=x
+ println("x = ", x)
end
+assert y==1
println()
-for k=1:4
- if !@ifmatch let (X,value(k))=(1,2)
- println("k=$k: X=$X")
- end
- println("k=",k)
+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
View
25 test/test_pdisp.jl
@@ -1,7 +1,6 @@
-load("utils/req.jl")
-load("pdispatch.jl")
-req("prettyshow/prettyshow.jl")
+
+load("pattern/pdispatch.jl")
mtable = PatternMethodTable(:f)
add(mtable, (@patmethod f(1) = 42))
@@ -24,7 +23,27 @@ 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
View
0  pattern/test/test_recode.jl → test/test_recode.jl
File renamed without changes
View
143 test/test_unify.jl
@@ -1,55 +1,96 @@
+
+load("pattern/req.jl")
+req("pattern/core.jl")
+req("pattern/composites.jl")
+load("pattern/pmatch.jl")
-load("pmatch.jl")
-load("utils/req.jl")
-req("utils/utils.jl")
+uni(x, y) = unify(aspattern(x), aspattern(y))
+pat_gt(x, y) = pattern_gt(aspattern(x), aspattern(y))
+pat_eq(x, y) = pattern_eq(aspattern(x), aspattern(y))
-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
+@symshowln uni(1, nonematch)
+@symshowln uni(nonematch, nonematch)
- 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)
+X, Y, Z = map(pvar, (:X, :Y, :Z))
+
+@symshowln uni(X, nonematch)
+@symshowln uni(X, 1)
+@symshowln uni(X, X)
+@symshowln uni(X, Y)
+
+@assert pat_gt(1, nonematch)
+@assert pat_eq(nonematch, nonematch)
+
+@assert pat_gt(X, nonematch)
+@assert pat_gt(X, 1)
+@assert pat_eq(X, X)
+@assert pat_eq(X, Y)
+
+@assert uni(1, nonematch)[1] == nonematch
+@assert uni(1, 1)[1] == Atom(1)
+@assert uni(1, 2)[1] == nonematch
+@assert uni(X, nonematch)[1] == nonematch
+@assert uni(X, 3)[1] == Atom(3)
+@assert uni(X, X)[1] == X
+@assert uni(X, Y)[1] == Y
+@assert uni(Y, X)[1] == X
+
+println()
+@symshowln uni(X, (1,2))
+@symshowln uni((X,), (1,2))
+@symshowln uni((X,Y), (1,2))
+@symshowln uni((1,Y), (1,2))
+@symshowln uni((1,Y), (X,2))
+@symshowln uni((1,X,Y), (X,Y,Z))
+@symshowln uni((1,Y,X), (X,Z,Y))
+@symshowln uni((1,X,Y), (X,Y,2))
+@symshowln uni((1,nonematch),(1,2))
+@symshowln uni((X,Y),((Y,Y),(Z,Z)))
+
+@assert uni(X, (1,2))[1] == aspattern((1,2))
+@assert uni((X,), (1,2))[1] == nonematch
+@assert uni((X,Y), (1,2))[1] == aspattern((1,2))
+@assert uni((1,Y), (1,2))[1] == aspattern((1,2))
+@assert uni((1,Y), (X,2))[1] == aspattern((1,2))
+@assert uni((1,X,Y), (X,Y,Z))[1] == aspattern((1,1,1))
+@assert uni((1,Y,X), (X,Z,Y))[1] == aspattern((1,1,1))
+@assert uni((1,X,Y), (X,Y,2))[1] == nonematch
+@assert uni((1,nonematch),(1,2))[1] == nonematch
+@assert uni((X,Y),((Y,Y),(Z,Z)))[1] == aspattern((((Z,Z),(Z,Z)),(Z,Z)))
+
+
+# println()
+# @showln uni(match(Any), match(Any))
+# @symshowln uni(match(Any), 1)
+# @symshowln uni(match(Real), 1)
+# @symshowln uni(match(Int), 1)
+# @symshowln uni(match(Float), 1)
+# @symshowln uni(nonematch, 1)
+
+# println()
+# @showln uni(match(Real), match(Real))
+# @symshowln uni(match(Real), match(Int))
+# @symshowln uni(match(Float), match(Int))
+
+#@pvar Xr::Real, Xi::Int, Xf::Float
+Xr, Xi, Xf = pvar(:Xr,Real), pvar(:Xi,Int), pvar(:Xf,Float)
+
+println()
+@symshowln uni(Xr, Xi)
+@symshow uni(Xi, Xf)
+
+println()
+@symshowln uni(Xi, 2)
+@symshowln uni(Xr, 2.0)
+@symshowln uni(Xi, 2.0)
+@symshowln uni(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
+# println()
+# @symshowln uni(match(Any), 1)
+# @symshowln uni(match(Any), X)
+# @symshowln uni(match(Any), Xi)
+
+
+println()
+@show z, s = uni(X,1)
+@show s[aspattern(((X,2),(X,3)))]
View
100 test/test_unify_vectors.jl
@@ -1,41 +1,79 @@
-load("pmatch.jl")
-load("utils/req.jl")
-req("utils/utils.jl")
+load("pattern/req.jl")
+req("pattern/core.jl")
+req("pattern/composites.jl")
+load("pattern/pmatch.jl")
+
let
- @pvar X, Y, Z
+ uni(x, y) = unify(aspattern(x), aspattern(y))
+
+ X, Y, Z = map(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}})
+ @symshowln uni(X, {1,2})
+ @symshowln uni({X,2}, {1,2})
+ @symshowln uni({X,1}, {1,2})
+ @symshowln uni({1,X}, {1,2})
+ @symshowln uni({1,X}, {Y,2})
+ @symshowln uni({1,X}, {1,2,3})
+ @symshowln uni({1,X,Y}, {1,2,3})
+ @symshowln uni({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})
+ @symshowln uni({1,X}, {X,Y})
+ @symshowln uni({1,X,Y}, {X,Y,Z})
+ @symshowln uni({1,X,Y}, {X,Y,1})
+ @symshowln uni({1,X,Y}, {X,Y,2})
+ @symshowln uni({1,Y,X}, {X,Z,Y})
+ @symshowln uni(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 Xi::Int, Xa::Array, Xv::Vector, Xm::Matrix
+# @symshowln uni(Xi, {1,2})
+# @symshowln uni(Xa, {1,2})
+# @symshowln uni(Xv, {1,2})
+# @symshowln uni(Xm, {1,2})
- println()
- @pvar Xai::Array{Int}
- @symshowln unify(Xai, {1,2})
- @symshowln unify(Xai, [1,2])
- @symshowln unify(Xa, [1,2,X])
+# println()
+# @pvar Xai::Array{Int}
+# @symshowln uni(Xai, {1,2})
+# @symshowln uni(Xai, [1,2])
+# @symshowln uni(Xa, [1,2,X])
+
+# # consider: Should this work? And force X to be an Int.
+# @symshowln uni(Xai, [1,2,X])
+
+
+# @symshowln uni(X, (1,2))
+# @symshowln uni((X,2), (1,2))
+# @symshowln uni((X,1), (1,2))
+# @symshowln uni((1,X), (1,2))
+# @symshowln uni((1,X), (Y,2))
+# @symshowln uni((1,X), (1,2,3))
+# @symshowln uni((1,X,Y), (1,2,3))
+# @symshowln uni((1,X), (1,(2,3)))
+
+# println()
+# @symshowln uni((1,X), (X,Y))
+# @symshowln uni((1,X,Y), (X,Y,Z))
+# @symshowln uni((1,X,Y), (X,Y,1))
+# @symshowln uni((1,X,Y), (X,Y,2))
+# @symshowln uni((1,Y,X), (X,Z,Y))
+# @symshowln uni(X, (1,X))
+
+# # println()
+# # @pvar Xi::Int, Xa::Array, Xv::Vector, Xm::Matrix
+# # @symshowln uni(Xi, (1,2))
+# # @symshowln uni(Xa, (1,2))
+# # @symshowln uni(Xv, (1,2))
+# # @symshowln uni(Xm, (1,2))
+
+# # println()
+# # @pvar Xai::Array(Int)
+# # @symshowln uni(Xai, (1,2))
+# # @symshowln uni(Xai, [1,2])
+# # @symshowln uni(Xa, [1,2,X])
- # consider: Should this work? And force X to be an Int.
- @symshowln unify(Xai, [1,2,X])
+# # # consider: Should this work? And force X to be an Int.
+# # @symshowln uni(Xai, [1,2,X])
end
Please sign in to comment.
Something went wrong with that request. Please try again.