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

Start Operators with no meaning section #1171

Merged
merged 3 commits into from
Nov 18, 2024
Merged
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
42 changes: 42 additions & 0 deletions mathics/builtin/no_meaning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# Note: this will be redone soon to pull no-meaning operator information from operators.yml out
# of the MathicsScanner project.
"""
Operators without Built-in Meanings

Not all operators recognized by the Mathics3 are associated with functions that have built‐in meanings.
You can use these operators as a way to build up your own notation within the Mathics3.
"""

from mathics.core.attributes import A_NO_ATTRIBUTES
from mathics.core.builtin import BinaryOperator


class Star(BinaryOperator):
r"""
Star <url>
:WML link:
https://reference.wolfram.com/language/ref/Star.html</url>

<dl>
<dt>'Star[$x$, $y$, ...]'
<dd>displays $x$ ⋆ $y$ ⋆ ...
</dl>

>> Star[x, y, z]
= x ⋆ y ⋆ z

>> a \[Star] b
= a ⋆ b
"""

attributes = A_NO_ATTRIBUTES
default_formats = False # Don't use any default format rules. Instead, see below.
formats = {
(("InputForm", "OutputForm", "StandardForm"), "Star[args__]"): (
'Infix[{args}, "⋆"]'
),
}

operator = "⋆" # \u22C6
summary_text = "star symbol"
4 changes: 3 additions & 1 deletion mathics/core/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,11 @@ def __init__(self, *args, **kwargs):

class BinaryOperator(Operator):
"""
Class for Builtin Binary Operators, e.g. Plus (+)
Class for Builtin Infix Operators (which includes Binary
operators), e.g. Plus (+).
"""

# Note: grouping must be Python string, not a Symbol.
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be OK if in the class definition, we use a Python string, if we convert it later into a Symbol. So, it would be a problem of contribute

Copy link
Contributor

Choose a reason for hiding this comment

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

I checked it out, and indeed grouping is used to build a Python str, that is parsed as a pattern object for defining formatting and boxing rules. So probably it is OK to keep is as a str.

grouping = "System`None" # NonAssociative, None, Left, Right

def __init__(self, *args, **kwargs):
Expand Down