Skip to content

Commit

Permalink
Support HoldPattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Sep 4, 2017
1 parent 70084c3 commit 3a9fed7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
5 changes: 2 additions & 3 deletions expreduce/builtin_pattern.go
Expand Up @@ -114,9 +114,7 @@ func GetPatternDefinitions() (defs []Definition) {
return res
},
})
defs = append(defs, Definition{
Name: "Repeated",
})
defs = append(defs, Definition{Name: "Repeated"})
defs = append(defs, Definition{
Name: "Optional",
toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) {
Expand All @@ -137,5 +135,6 @@ func GetPatternDefinitions() (defs []Definition) {
// Not fully supported. Don't document
OmitDocumentation: true,
})
defs = append(defs, Definition{Name: "HoldPattern"})
return
}
7 changes: 7 additions & 0 deletions expreduce/matchq.go
Expand Up @@ -124,6 +124,13 @@ func NewMatchIter(a Ex, b Ex, pm *PDManager, es *EvalState) (matchIter, bool) {
}
}
}
// Special case for HoldPattern
holdPattern, isHoldPattern := HeadAssertion(b, "System`HoldPattern")
if isHoldPattern {
if len(holdPattern.Parts) == 2 {
return NewMatchIter(a, holdPattern.Parts[1], pm, es)
}
}

// Continue normally
_, aIsFlt := a.(*Flt)
Expand Down

0 comments on commit 3a9fed7

Please sign in to comment.