Skip to content

Format: accept a named pattern or a blank as the argument, e.g. Format[t_h] := ... - #1997

Merged
rocky merged 1 commit into
Mathics3:masterfrom
tombouctou:fix-format-named-pattern-lhs
Oct 16, 2026
Merged

rocky merged 1 commit into
Mathics3:masterfrom
tombouctou:fix-format-named-pattern-lhs

Conversation

@tombouctou

Copy link
Copy Markdown
Collaborator

eval_assign_format replaced the left-hand side of a Format definition by its head before looking for the tag. For a named pattern or a blank the head is Pattern or Blank, so the assignment failed:

In[1]:= Format[A_G] := "g" /; Length[A] > 1
SetDelayed::write: Tag Pattern in A_G is Protected.
Out[1]= $Failed

In WMA this defines a format for G; Format[_G] and Format[t:G[__]] work the same way.

This PR keeps named patterns and blanks as they are, so the tag (G) is found inside them by collect_lhs_names_and_upset_dont_allow_custom, as for other assignments. Related: #898.

Tests: new cases in test/builtin/assignments/test_assignment.py (test_assignment).

🤖 Generated with Claude Code

…t[t_h] := ...

eval_assign_format replaced the left-hand side by its head, so for
Format[A_G] := ... the tag became Pattern and the assignment failed with
"Tag Pattern in A_G is Protected". Keep named patterns and blanks as
they are, so the tag (G) is found inside them, as for other assignments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mmatera

mmatera commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

LGTM

@rocky

rocky commented Oct 16, 2026

Copy link
Copy Markdown
Member

@mmatera I am guessing then you have no problem with accepting Claude Code commits, right?

@mmatera

mmatera commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

@mmatera I am guessing then you have no problem with accepting Claude Code commits, right?

As I just said in #1991 (comment), in principle I am OK with it, as far as it does not flood our review capacity.

@rocky

rocky commented Oct 16, 2026

Copy link
Copy Markdown
Member

@mmatera I am guessing then you have no problem with accepting Claude Code commits, right?

As I just said in #1991 (comment), in principle I am OK with it, as far as it does not flood our review capacity.

To me, the sad part is that there really is this much wrong with the code.

I will be focusing right now on going over the PRs. So far, everything I've seen makes sense and is good.

@rocky

rocky commented Oct 16, 2026

Copy link
Copy Markdown
Member

Thanks!

@rocky
rocky merged commit 1fbc4bd into Mathics3:master Oct 16, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants