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

Fix arithmetic format #892

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Fix arithmetic format #892

wants to merge 4 commits into from

Conversation

mmatera
Copy link
Contributor

@mmatera mmatera commented Jul 29, 2023

This PR is a first step to improving the way in which arithmetic expressions are formatted. I started trying to fix how DirectedInfinity expressions are formatted, using the standard syntax of WL. However, on each attempt to do that, I collide against the flawed design of our formatting system.
At this point, this is getting large, and still there is a lot of work to do. However, with these changes many expressions are formatted in a closer way than in WMA, and I did some steps in order to disentangle the code.
I will leave this here as a draft for a while.

@mmatera mmatera marked this pull request as draft July 29, 2023 01:27
.
. Format[Dice[n_Integer ? (1 <= #1 <= 6&)], OutputForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{Plus[1, Times[-1, p]], 0.5}, r]}]}, ImageSize -> Tiny]]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not perfect, but at least I got something less weird than what we have in master.

# Force parenthesis by adjusting the surrounding context's precedence value,
# We can't change the precedence for the number since it, doesn't
# have a precedence value.
element_prec = 480
Copy link
Member

Choose a reason for hiding this comment

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

I am pretty sure this is not the right way to fix this. There is always a precedence for all atoms.

@rocky
Copy link
Member

rocky commented Jul 30, 2023

You were going to come up with a proof of concept by writing MakeBox in Mathics3.

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.

2 participants