Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera committed Nov 16, 2022
2 parents b81ccb8 + c54808f commit 4be98fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. contents::

CHANGES
=======
*******

5.0.3dev0
---------
Expand Down Expand Up @@ -52,7 +52,8 @@ Bugs
# ``0`` with a given precision (like in ```0`3```) is now parsed as ``0``, an integer number.
#. ``RandomSample`` with one list argument now returns a random ordering of the list items. Previously it would return just one item.
#. Rules of the form ``pat->Condition[expr, cond]`` are handled as in WL. The same works for nested `Condition` expressions. Also, comparisons among these rules was improved.

#. ``mathics.core.Pattern.create`` now catches the case when the input parameter is not an `Atom` or an `Expression`.


Enhancements
++++++++++++
Expand Down
5 changes: 5 additions & 0 deletions mathics/builtin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,11 @@ def get_string_value(self):

def sameQ(self, expr) -> bool:
"""Mathics SameQ"""
if expr is self:
return True
# Otherwise, we need to convert
# self into an to expression
# to avoid an infinite loop...
return self.to_expression().sameQ(expr)

def do_format(self, evaluation, format):
Expand Down
9 changes: 4 additions & 5 deletions mathics/core/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ def create(expr: BaseElement) -> "Pattern":
by calling the method ``to_expression``, and then call the function
again with this new object as input.
"""
if not isinstance(expr, (Atom, Expression)):
expr = expr.to_expression()

name = expr.get_head_name()
pattern_object = pattern_objects.get(name)
if pattern_object is not None:
Expand All @@ -97,8 +94,10 @@ def create(expr: BaseElement) -> "Pattern":
return AtomPattern(expr)
elif isinstance(expr, Expression):
return ExpressionPattern(expr)
# Otherwise, try to get an expression and
# call again.
# To handle Boxes and other possible objects that
# can be converted into expressions, convert expr to
# expression and call this function
# again:
return Pattern.create(expr.to_expression())

def match(
Expand Down

0 comments on commit 4be98fc

Please sign in to comment.