Skip to content

Overridable node visitors instead of typed-nodes in expression trees #75

@Upabjojr

Description

@Upabjojr

The current MatchPy implementation defines expression trees and allows expression trees to be overloaded by external library (as it is done in SymPy's connector to MatchPy). Unfortunately, the current MatchPy implementation relies on types and isinstance( ) calls to determine the expression node.
For example:

  • isinstance(label, Wildcard) to check if a label is a wildcard,
  • isinstance(expression, Operation)
  • isinstance(subpattern, CommutativeOperation)
  • isinstance(expression, AssociativeOperation)
  • isinstance(subpattern, OneIdentityOperation)

The first one is quite tricky in SymPy because it needs to define a new class that is both a MatchPy and SymPy object.

There are other approaches to expression tree that do not defined typed nodes (i.e. classes that represent a particular type of node). For example, protosym has a unique class to define many types of nodes.

Does it make sense to create an overridable method is check whether a node is a wildcard/operation/associative operation/commutative operation/etc... so that custom libraries may define their way to visit their expression trees?

Metadata

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