Repository navigation
Infix, Prefix, Postfix: do not format their first argument as a whole - #2014
Merged
Merged
Conversation
Format[p[t__]] := Infix[p[t], "~"] made printing p[a, b] hit $RecursionLimit. Before boxing, do_format_element formats every subexpression of the result of a format rule, so it formatted p[a, b] inside the Infix again, which gave the same Infix, and so on. Infix, Prefix and Postfix display only the elements of their first argument, never the argument itself, so only those elements are formatted now. This is how WMA handles such definitions, which are the usual way to give an expression an operator form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Makes sense. LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A format rule that wraps the expression it formats in
Infix,PrefixorPostfixmade printing hit$RecursionLimit:Before boxing,
do_format_elementformats every subexpression of the result of a format rule. It therefore formattedp[a, b]inside theInfixagain, which gave the sameInfix, and so on.Infix,PrefixandPostfixdisplay only the elements of their first argument, never the argument itself. Now only those elements are formatted. Defining a format this way is the usual way to give an expression an operator form, and code written for WMA relies on it: the Toda-bracket package we are running on Mathics3 (see #2001) hasFormat[t_o] := Infix[t, "∘"] /; Length[t] > 1.Tests: five new cases in
test_layoutintest/format/test_format.py. All five fail on master.🤖 Generated with Claude Code