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

Remove "precedence" in operator classes... #1080

Merged
merged 1 commit into from
Aug 31, 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
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
CHANGES
=======


New Builtins
++++++++++++

Expand All @@ -12,6 +13,11 @@ Compatibility

* ``GetEnvironment`` expanded to handle ``[]`` and ``{var1, var2,...}`` forms

Internals
---------

Operator precedence has been gone over and is picked up in tables from the Mathics Scanner project.


7.0.0
-----
Expand Down Expand Up @@ -63,7 +69,7 @@ Compatibility


Internals
---
---------

* ``eval_abs`` and ``eval_sign`` extracted from ``Abs`` and ``Sign`` and added to ``mathics.eval.arithmetic``.
* Maximum number of digits allowed in a string set to 7000 and can be adjusted using environment variable
Expand Down
7 changes: 0 additions & 7 deletions mathics/builtin/arithfns/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class Divide(BinaryOperator):

grouping = "Left"
operator = "/"
precedence = 470

rules = {
"Divide[x_, y_]": "Times[x, Power[y, -1]]",
Expand Down Expand Up @@ -208,7 +207,6 @@ class Minus(PrefixOperator):
}

operator = "-"
precedence = 480

rules = {
"Minus[x_]": "Times[-1, x]",
Expand Down Expand Up @@ -283,7 +281,6 @@ class Plus(BinaryOperator, SympyFunction):
}

operator = "+"
precedence = 310

summary_text = "add"

Expand Down Expand Up @@ -435,7 +432,6 @@ class Power(BinaryOperator, MPMathFunction):

nargs = {2}
operator = "^"
precedence = 590

rules = {
"Power[]": "1",
Expand Down Expand Up @@ -556,8 +552,6 @@ class Subtract(BinaryOperator):
grouping = "Left"

operator = "-"
precedence = 310
precedence_parse = 311
rules = {
"Subtract[x_, y_]": "Plus[x, Times[-1, y]]",
}
Expand Down Expand Up @@ -623,7 +617,6 @@ class Times(BinaryOperator, SympyFunction):
operator = "*"
operator_display = " "

precedence = 400
rules = {}

# FIXME Note this is deprecated in 1.11
Expand Down
4 changes: 0 additions & 4 deletions mathics/builtin/assignments/assign_binaryop.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ class PreIncrement(PrefixOperator):

attributes = A_HOLD_FIRST | A_PROTECTED | A_READ_PROTECTED
operator = "++"
precedence = 660

rules = {
"++x_": "x = x + 1",
Expand Down Expand Up @@ -195,7 +194,6 @@ class PreDecrement(PrefixOperator):
"""

operator = "--"
precedence = 660
attributes = A_HOLD_FIRST | A_PROTECTED | A_READ_PROTECTED

rules = {
Expand Down Expand Up @@ -225,7 +223,6 @@ class SubtractFrom(BinaryOperator):
attributes = A_HOLD_FIRST | A_PROTECTED
grouping = "Right"
operator = "-="
precedence = 100

rules = {
"x_ -= dx_": "x = x - dx",
Expand All @@ -251,7 +248,6 @@ class TimesBy(BinaryOperator):
"""

operator = "*="
precedence = 100
attributes = A_HOLD_FIRST | A_PROTECTED
grouping = "Right"

Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/assignments/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ class Set(BinaryOperator, _SetOperator):
}

operator = "="
precedence = 40

summary_text = "assign a value"

Expand Down Expand Up @@ -372,7 +371,6 @@ class UpSet(BinaryOperator, _SetOperator):
attributes = A_HOLD_FIRST | A_PROTECTED | A_SEQUENCE_HOLD
grouping = "Right"
operator = "^="
precedence = 40

summary_text = (
"set value and associate the assignment with symbols that occur at level one"
Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/assignments/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ class Remove(Builtin):

attributes = A_HOLD_ALL | A_LOCKED | A_PROTECTED

precedence = 670
summary_text = "remove the definition of a symbol"

def eval(self, symb, evaluation):
Expand Down Expand Up @@ -256,7 +255,6 @@ class Unset(PostfixOperator):
"norep": "Assignment on `2` for `1` not found.",
"usraw": "Cannot unset raw object `1`.",
}
precedence = 670
summary_text = "unset a value of the LHS"

def eval(self, expr, evaluation):
Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/atomic/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ class InterpretationBox(PrefixOperator):
"""

operator = "\\!"
precedence = 670
summary_text = "interpret boxes as an expression"

def eval(self, boxes, evaluation: Evaluation):
Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/atomic/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ class Definition(Builtin):
"""

attributes = A_HOLD_ALL | A_PROTECTED
precedence = 670
summary_text = "give values of a symbol in a form that can be stored in a package"

def format_definition(self, symbol, evaluation, grid=True):
Expand Down Expand Up @@ -428,7 +427,6 @@ class Information(PrefixOperator):
options = {
"LongForm": "True",
}
precedence = 0
summary_text = "get information about all assignments for a symbol"

def format_definition(self, symbol, evaluation, options, grid=True):
Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/exp_structure/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class MapApply(BinaryOperator):

grouping = "Right"
operator = "@@@"
precedence = 620

rules = {
"MapApply[f_, expr_]": "Apply[f, expr, {1}]",
Expand Down
3 changes: 0 additions & 3 deletions mathics/builtin/files_io/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ class Get(PrefixOperator):
options = {
"Trace": "False",
}
precedence = 720
summary_text = "read in a file and evaluate commands in it"

def eval(self, path: String, evaluation: Evaluation, options: dict):
Expand Down Expand Up @@ -567,7 +566,6 @@ class Put(BinaryOperator):
"""

operator = ">>"
precedence = 30
summary_text = "write an expression to a file"

def eval(self, exprs, filename, evaluation):
Expand Down Expand Up @@ -663,7 +661,6 @@ class PutAppend(BinaryOperator):
"""

operator = ">>>"
precedence = 30
summary_text = "append an expression to a file"

def eval(self, exprs, filename, evaluation):
Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/functional/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class Function(PostfixOperator):
"""

operator = "&"
precedence = 90
attributes = A_HOLD_ALL | A_PROTECTED

messages = {
Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/functional/apply_fns_to_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class Apply(BinaryOperator):

summary_text = "apply a function to a list, at specified levels"
operator = "@@"
precedence = 620
grouping = "Right"

options = {
Expand Down Expand Up @@ -130,7 +129,6 @@ class Map(BinaryOperator):

summary_text = "map a function over a list, at specified levels"
operator = "/@"
precedence = 620
grouping = "Right"

options = {
Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ class Postfix(BinaryOperator):
grouping = "Left"
operator = "//"
operator_display = None
precedence = 70
summary_text = "postfix form"


Expand Down Expand Up @@ -327,7 +326,6 @@ class Prefix(BinaryOperator):
grouping = "Right"
operator = "@"
operator_display = None
precedence = 640
summary_text = "prefix form"


Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/list/eol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,6 @@ class Span(BinaryOperator):
"""

operator = ";;"
precedence = 305
summary_text = "general specification for spans or blocks of elements"


Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ class MessageName(BinaryOperator):
messages = {"messg": "Message cannot be set to `1`. It must be set to a string."}
summary_text = "message identifyier"
operator = "::"
precedence = 750
rules = {
"MakeBoxes[MessageName[symbol_Symbol, tag_String], "
"f:StandardForm|TraditionalForm|OutputForm]": (
Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/numbers/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ class Derivative(PostfixOperator, SympyFunction):
attributes = A_N_HOLD_ALL
default_formats = False
operator = "'"
precedence = 670
rules = {
"MakeBoxes[Derivative[n__Integer][f_], "
" form:StandardForm|TraditionalForm]": (
Expand Down Expand Up @@ -1752,7 +1751,6 @@ class SeriesData(Builtin):

# TODO: Implement sum, product and composition of series

precedence = 1000
summary_text = "power series of a variable about a point"

def eval_reduce(
Expand Down
10 changes: 0 additions & 10 deletions mathics/builtin/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class Rule_(BinaryOperator):

name = "Rule"
operator = "->"
precedence = 120
attributes = A_SEQUENCE_HOLD | A_PROTECTED
grouping = "Right"
needs_verbatim = True
Expand All @@ -122,7 +121,6 @@ class RuleDelayed(BinaryOperator):
attributes = A_SEQUENCE_HOLD | A_HOLD_REST | A_PROTECTED
needs_verbatim = True
operator = ":>"
precedence = 120
summary_text = "a rule that keeps the replacement unevaluated"


Expand Down Expand Up @@ -335,7 +333,6 @@ class ReplaceAll(BinaryOperator):
grouping = "Left"
needs_verbatim = True
operator = "/."
precedence = 110

messages = {
"reps": "`1` is not a valid replacement rule.",
Expand Down Expand Up @@ -391,7 +388,6 @@ class ReplaceRepeated(BinaryOperator):
grouping = "Left"
needs_verbatim = True
operator = "//."
precedence = 110

messages = {
"reps": "`1` is not a valid replacement rule.",
Expand Down Expand Up @@ -544,7 +540,6 @@ class PatternTest(BinaryOperator, PatternObject):

arg_counts = [2]
operator = "?"
precedence = 680
summary_text = "match to a pattern conditioned to a test result"

def init(
Expand Down Expand Up @@ -763,7 +758,6 @@ class Alternatives(BinaryOperator, PatternObject):
arg_counts = None
needs_verbatim = True
operator = "|"
precedence = 160
summary_text = "match to any of several patterns"

def init(
Expand Down Expand Up @@ -1097,7 +1091,6 @@ class Optional(BinaryOperator, PatternObject):
"MakeBoxes[Verbatim[Optional][Verbatim[_]], f:StandardForm|TraditionalForm|InputForm|OutputForm]": '"_."',
}
operator = ":"
precedence = 140
summary_text = "an optional argument with a default value"

def init(
Expand Down Expand Up @@ -1381,7 +1374,6 @@ class Repeated(PostfixOperator, PatternObject):
}

operator = ".."
precedence = 170
summary_text = "match to one or more occurrences of a pattern"

def init(
Expand Down Expand Up @@ -1451,7 +1443,6 @@ class RepeatedNull(Repeated):
"""

operator = "..."
precedence = 170
summary_text = "match to zero or more occurrences of a pattern"

def init(
Expand Down Expand Up @@ -1533,7 +1524,6 @@ class Condition(BinaryOperator, PatternObject):
# Don't know why this has attribute HoldAll in Mathematica
attributes = A_HOLD_REST | A_PROTECTED
operator = "/;"
precedence = 130
summary_text = "conditional definition"

def init(
Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/procedural.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class CompoundExpression(BinaryOperator):

attributes = A_HOLD_ALL | A_PROTECTED | A_READ_PROTECTED
operator = ";"
precedence = 10

summary_text = "execute expressions in sequence"

Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/specialfns/gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ class Factorial(PostfixOperator, MPMathFunction):

mpmath_name = "factorial"
operator = "!"
precedence = 610
summary_text = "factorial"


Expand Down Expand Up @@ -198,7 +197,6 @@ class Factorial2(PostfixOperator, MPMathFunction):

attributes = A_NUMERIC_FUNCTION | A_PROTECTED
operator = "!!"
precedence = 610
mpmath_name = "fac2"
sympy_name = "factorial2"
messages = {
Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/string/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ class StringJoin(BinaryOperator):

attributes = A_FLAT | A_ONE_IDENTITY | A_PROTECTED
operator = "<>"
precedence = 600
summary_text = "join strings together"

def eval(self, items, evaluation):
Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/string/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ class StringExpression(BinaryOperator):

attributes = A_FLAT | A_ONE_IDENTITY | A_PROTECTED
operator = "~~"
precedence = 135

messages = {
"invld": "Element `1` is not a valid string or pattern element in `2`.",
Expand Down
Loading