diff --git a/expreduce/blank.go b/expreduce/blank.go index a0a0918..df28b93 100644 --- a/expreduce/blank.go +++ b/expreduce/blank.go @@ -19,7 +19,7 @@ func IsBlankTypeOnly(e Ex) bool { return false } -func IsBlankTypeCapturing(e Ex, target Ex, t string, pm *PDManager, cl *CASLogger) (bool, *PDManager) { +func IsBlankTypeCapturing(e Ex, target Ex, head Ex, pm *PDManager, cl *CASLogger) (bool, *PDManager) { // Similar to IsBlankType, but will capture target into es.patternDefined // if there is a valid match. asPattern, patternOk := HeadAssertion(e, "Pattern") @@ -44,12 +44,7 @@ func IsBlankTypeCapturing(e Ex, target Ex, t string, pm *PDManager, cl *CASLogge if len(parts) < 2 { matchesHead = true } else { - asSymbol, symbolOk := parts[1].(*Symbol) - if symbolOk { - if asSymbol.Name == t { - matchesHead = true - } - } + matchesHead = IsSameQ(head, parts[1], cl) } cl.Debugf("%v", matchesHead) if matchesHead { @@ -84,7 +79,6 @@ func IsBlankTypeCapturing(e Ex, target Ex, t string, pm *PDManager, cl *CASLogge asBS, bsOk := HeadAssertion(e, "BlankSequence") asBNS, bnsOk := HeadAssertion(e, "BlankNullSequence") if blankOk || bsOk || bnsOk { - var asSymbol *Symbol parts := []Ex{} if blankOk { parts = asBlank.Parts @@ -96,10 +90,7 @@ func IsBlankTypeCapturing(e Ex, target Ex, t string, pm *PDManager, cl *CASLogge if len(parts) < 2 { return true, pm } - asSymbol, symbolOk := parts[1].(*Symbol) - if symbolOk { - return asSymbol.Name == t, pm - } + return IsSameQ(head, parts[1], cl), pm } return false, pm } diff --git a/expreduce/builtin_pattern.go b/expreduce/builtin_pattern.go index f210da7..d87a53a 100644 --- a/expreduce/builtin_pattern.go +++ b/expreduce/builtin_pattern.go @@ -91,6 +91,8 @@ func GetPatternDefinitions() (defs []Definition) { // Test pinning in orderless &SameTest{"{{b[[1]],b},{y,a},{y,c},{b[[1]],b},{x,a},{y,c},{b[[1]],b},{x,c},{y,a},{b[[1]],b},{x,a},{x,c}}", "pats"}, + + &SameTest{"True", "MatchQ[(a+b)[testsym],Blank[(a+b)]]"}, }, KnownFailures: []TestInstruction{ // Test order of pattern checking diff --git a/expreduce/matchq.go b/expreduce/matchq.go index 8a2a1c2..cde915e 100644 --- a/expreduce/matchq.go +++ b/expreduce/matchq.go @@ -147,24 +147,23 @@ func NewMatchIter(a Ex, b Ex, pm *PDManager, es *EvalState) (matchIter, bool) { } // This initial value is just a randomly chosen placeholder - // TODO, convert headStr to symbol type, have Ex implement getHead() Symbol - headStr := "Unknown" + var headEx Ex if aIsFlt { - headStr = "Real" + headEx = &Symbol{"Real"} } else if aIsInteger { - headStr = "Integer" + headEx = &Symbol{"Integer"} } else if aIsString { - headStr = "String" + headEx = &Symbol{"String"} } else if aIsExpression { - headStr = aExpression.Parts[0].String() + headEx = aExpression.Parts[0] } else if aIsSymbol { - headStr = "Symbol" + headEx = &Symbol{"Symbol"} } else if aIsRational { - headStr = "Rational" + headEx = &Symbol{"Rational"} } if IsBlankTypeOnly(b) { - ibtc, ibtcNewPDs := IsBlankTypeCapturing(b, a, headStr, pm, &es.CASLogger) + ibtc, ibtcNewPDs := IsBlankTypeCapturing(b, a, headEx, pm, &es.CASLogger) if ibtc { return &dummyMatchIter{true, ibtcNewPDs, true}, true }