Skip to content

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

Open
@rocky

Description

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_]"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions