Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions mathics/core/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ def has_symbol(self, symbol_name: str) -> bool:
if hasattr(element, "has_symbol")
)

def restructure(self, head, elements, evaluation, structure_cache=None, deps=None):
def restructure(self, head, elements, evaluation, structure_cache={}, deps=None):
"""Faster equivalent of: ``Expression(head, *elements)``

The caller guarantees that _all_ elements are either from
Expand Down Expand Up @@ -1924,7 +1924,7 @@ def _is_neutral_head(head, cache, evaluation):
return _is_neutral_symbol(head.get_name(), cache, evaluation)


def structure(head, origins, evaluation, structure_cache=None):
def structure(head, origins, evaluation, structure_cache={}):
"""
Creates a Structure for building Expressions with head "head" and elements
originating (exclusively) from "origins" (elements are passed into the functions
Expand All @@ -1942,22 +1942,20 @@ def structure(head, origins, evaluation, structure_cache=None):

if isinstance(origins, (Expression, Structure)):
cache = origins._cache
if cache is not None and not _is_neutral_head(
head, structure_cache, evaluation
):
cache = None
if cache and not _is_neutral_head(head, structure_cache, evaluation):
cache = {}
elif isinstance(origins, (list, tuple)):
if _is_neutral_head(head, structure_cache, evaluation):
cache = ExpressionCache.union(origins, evaluation)
else:
cache = None
cache = {}
else:
raise ValueError("expected Expression, Structure, tuple or list as orig param")

if cache is None:
return UnlinkedStructure(head)
else:
if cache:
return LinkedStructure(head, cache)
else:
return UnlinkedStructure(head)


def atom_list_constructor(evaluation, head, *atom_names):
Expand Down
Loading