Skip to content

Commit acb3265

Browse files
authored
More docs and annotations about Pattern and Rules (#806)
* Improving documentation of the Pattern and Rule code * adding the optional parameter `evaluation` to the `create_pattern` function.
1 parent d80fec1 commit acb3265

File tree

5 files changed

+584
-153
lines changed

5 files changed

+584
-153
lines changed

mathics/builtin/base.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from mathics.core.convert.python import from_bool
2525
from mathics.core.convert.sympy import from_sympy
2626
from mathics.core.definitions import Definition
27+
from mathics.core.evaluation import Evaluation
2728
from mathics.core.exceptions import MessageException
2829
from mathics.core.expression import Expression, SymbolDefault
2930
from mathics.core.interrupt import BreakInterrupt, ContinueInterrupt, ReturnInterrupt
@@ -932,14 +933,16 @@ class PatternObject(BuiltinElement, Pattern):
932933

933934
arg_counts: List[int] = []
934935

935-
def init(self, expr):
936-
super().init(expr)
936+
def init(self, expr, evaluation: Optional[Evaluation] = None):
937+
super().init(expr, evaluation=evaluation)
937938
if self.arg_counts is not None:
938939
if len(expr.elements) not in self.arg_counts:
939940
self.error_args(len(expr.elements), *self.arg_counts)
940941
self.expr = expr
941-
self.head = Pattern.create(expr.head)
942-
self.elements = [Pattern.create(element) for element in expr.elements]
942+
self.head = Pattern.create(expr.head, evaluation=evaluation)
943+
self.elements = [
944+
Pattern.create(element, evaluation=evaluation) for element in expr.elements
945+
]
943946

944947
def error(self, tag, *args):
945948
raise PatternError(self.get_name(), tag, *args)

0 commit comments

Comments
 (0)