Skip to content

Conversation

@rocky
Copy link
Member

@rocky rocky commented Jun 29, 2025

These are changes and slight bugs encounted in PR #1413

As a separate PR, this should reduce the size and effort for dealing with #1413, which I'll rebase after this is merged

in adding location information.

The hope here is to reduce the size and effort for dealing with the
location changes.
@rocky rocky requested a review from mmatera June 29, 2025 21:34
summary_text = "match to any single expression"

def match(self, expression: Expression, pattern_context: dict):
def match(self, expression: BaseElement, pattern_context: dict):
Copy link
Member Author

Choose a reason for hiding this comment

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

Change to BaseElement reduces mypy complaints. It may very well be that Expression is more correct, but I don't know how to get mypy to agree with this. So here I switched rather than argue with mypy.

"""
Load definitions from Builtin classes, autoload files and extension modules.
"""
from mathics.core.load_builtin import (
Copy link
Member Author

@rocky rocky Jun 29, 2025

Choose a reason for hiding this comment

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

I ran into circular dependencies from changes in #1413, and this fixed that.

However, moving this down also feels right in that there are the other imports here.

What this is telling us is that load_buildin_definitions() should be moved out of this module.

# We have the character name ImaginaryI and ImaginaryJ, but we should
# have the *operator* name, "I".
special_symbols["\uF74F"] = special_symbols["\uF74E"] = "I"
special_symbols["\uf74f"] = special_symbols["\uf74e"] = "I"
Copy link
Member Author

Choose a reason for hiding this comment

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

This one is weird in that black or some formatter decided to do this.

Again, I'd rather switch than argue with whatever formatter decided this.



def parse(definitions, feeder: LineFeeder) -> Any:
def parse(definitions, feeder: LineFeeder) -> Optional[BaseElement]:
Copy link
Member Author

@rocky rocky Jun 29, 2025

Choose a reason for hiding this comment

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

Adding more precise type annotations for mypy.

return (1, 1)

@property
def short_name(self) -> str:
Copy link
Member Author

@rocky rocky Jun 29, 2025

Choose a reason for hiding this comment

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

Using short_name came up in working on TraceEvaluation. I am surprised we never needed short_name for patterns before.

for rule in rules:
result = rule.apply(self, evaluation, fully=True)
if result is not None and not result.sameQ(self):
if result.is_literal:
Copy link
Member Author

Choose a reason for hiding this comment

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

This is probably just an oversight on our part. Stuff like this becomes apparent when you start looking at traces of expression evaluations.

"""

pass
@property
Copy link
Member Author

Choose a reason for hiding this comment

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

I thiink @mmatera had mentioned that redfining True and False in MMA, if it is possible, will horribly break MMA.

I recall we had a discussion about whether the parent class SymbolConstant could be a literal. Right now it is not. However True and False I have a harder time seeing why it wouldn't be literal.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, True and False, like List are some of the few symbols having the attribute Locked. I guess that this is because the evaluation relies on the fixed value of these symbols (but it is not especified anywhere)

* the evaluation is a literal that evaluates to the same thing,
* evaluating a Symbol which the Symbol.
* Showing the return value of a ListExpression literal
* Evaluating Pattern[] which define a pattern.
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is inspired by looking at TraceEvaluation. There is no benefit in watching an evaluation of _, n_, or n_Integer.

@rocky rocky merged commit 253e925 into master Jul 4, 2025
14 checks passed
@rocky rocky deleted the less-major-changes branch July 4, 2025 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants