Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Bugs
# Reading certain GIFs now work again
#. ``Random[]`` works now.
#. ``RandomSample`` with one list argument now returns a random ordering of the list items. Previously it would return just one item.
#. `RowBox` now have an `elements` attribute, in a way that expressions like `Part[RowBox[{"a"}],1]` does not raises an unhandled exception.
#. Origin placement corrected on ``ListPlot`` and ``LinePlot``.
#. Fix long-standing bugs in Image handling
#. Some scikit image routines line ``EdgeDetect`` were getting omitted due to overly stringent PyPI requirements
Expand All @@ -175,6 +176,7 @@ PyPI Package requirements

Mathics3 aims at a more richer set of functionality.


Therefore NumPy and Pillow (9.10 or later) are required Python
packages where they had been optional before. In truth, probably
running Mathics without one or both probably did not work well if it
Expand Down
20 changes: 14 additions & 6 deletions mathics/builtin/box/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ def eval_list(self, boxes, evaluation):
result = RowBox(*items)
return result

@property
def elements(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like something in the code or the API is wrong here.

I get nervous about "properties" doing possibly unbounded calculations such as self.to_expressions().

If I understand correctly, the caller somehow knows this is a compound Expression/Element and assumes that therefore it has an .element attribute which is of type Expression?

It feels like what should be happening that the caller should be asking instead for a conversion, that is, should be calling to_expression().elements

I need to think about this more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like something in the code or the API is wrong here.

Probably it is, but I tried to build over the existing API. At least, this is "localized" in this class.

I get nervous about "properties" doing possibly unbounded calculations such as self.to_expressions().

If I understand correctly, the caller somehow knows this is a compound Expression/Element and assumes that therefore it has an .element attribute which is of type Expression?

The problem is that Part assumes that an Expression has a property elements. This just provides the property by creating an Expression. A different possibility would be to implement a different rule for working with RowBoxes. I thought this change was simpler, but maybe there is a better approach.

It feels like what should be happening that the caller should be asking instead for a conversion, that is, should be calling to_expression().elements

I need to think about this more.

Sure.

if self._elements is None:
items = tuple(
item.to_expression() if isinstance(item, BoxElementMixin) else item
for item in self.items
)
self._elements = ListExpression(*items)
return self._elements

def get_head(self):
return SymbolRowBox

def init(self, *items, **kwargs):
# TODO: check that each element is an string or a BoxElementMixin
self.box_options = {}
Expand Down Expand Up @@ -275,13 +288,8 @@ def to_expression(self) -> Expression:
a sequence and finally, a ``RowBox`` is built. Then, riffle needs an expression as an argument. To get it,
in the apply method, this function must be called.
"""
if self._elements is None:
self._elements = tuple(
item.to_expression() if isinstance(item, BoxElementMixin) else item
for item in self.items
)

return Expression(SymbolRowBox, ListExpression(*self._elements))
return Expression(SymbolRowBox, self.elements)


class ShowStringCharacters(Builtin):
Expand Down