Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mathics3 signature pattern matching fails when a function has the FLAT attribute #1381

Open
rocky opened this issue Feb 11, 2025 · 0 comments

Comments

@rocky
Copy link
Member

rocky commented Feb 11, 2025

Description

When a builtin function has the Flat attribute (as happens in the Union builtin), and we have a particular kind of pattern, the matching will not pass a full flattened list.

How to Reproduce

Consider this pattern docstring for Union:

        "Union[lists__, SameTest->sametest_]"

If we encounter:

Union[{1, -1, -2}, {2, 3}, SameTest -> (Abs[#1] == Abs[#2] &)]

and Union has the "Flat" attribute (flatten lists), then the pattern matches, but the eval() method gets passed {1, -1, -2} for list rather than {{1, -1, -2, 2, 3}.

If instead Union does not have the Flat attribute, the pattern matches, and the eval() method gets passed {{1, -1, -2}, {2, 3}} in list.

Context

This behavior is seen in the code. Currently, we omit the flat attribute for Union because of this behavior.

The actual pattern used is a little more complicated since it does not appear in the Union class but instead appears in the Abstract base class _SetOperation as:

"%(name)s[lists__, SameTest->sametest_]"
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

No branches or pull requests

1 participant