Skip to content

Add an Mathics3 Atom for an Association #1868

Merged
rocky merged 16 commits into
masterfrom
add-Association-atom
Jul 24, 2026
Merged

Add an Mathics3 Atom for an Association #1868
rocky merged 16 commits into
masterfrom
add-Association-atom

Conversation

@rocky

@rocky rocky commented Jul 23, 2026

Copy link
Copy Markdown
Member

First cut at converting an Association Expression into a more performant Association Atom.

The Association Atom is an object that wraps a Python dictionary of BaseElements and includes the additional Mathics3 Atom methods typically associated with Atoms.

Since it is based on Python dictionaries, it handles key lookup and update more efficiently.

For now, we still have several eval (complicated and inefficient) functions for an S-Expression-based representation. And that is because there still may be situations where we encounter S-Expression-based Associations.

Over time, this code will probably be revised to avoid this, and in conjunction with that, the additional eval functions will be removed as they become unnecessary.

More eval code has been moved from mathics.builtin to mathics.eval.

Argument checking added to affected Modules.

Several bugs in Association handling were fixed. In particular, the Ordering properties of Associations with respect to other objects like Strings. Some output routines were not displaying as an Association properly.

@rocky
rocky requested a review from mmatera July 23, 2026 15:00
@rocky rocky changed the title Add association atom Add an Mathics3 Atom for an Association Jul 23, 2026
@rocky
rocky force-pushed the add-Association-atom branch from 1ae602f to e207cb1 Compare July 23, 2026 16:28
@rocky
rocky force-pushed the add-Association-atom branch from e207cb1 to 8d6770d Compare July 23, 2026 16:52
@mmatera

mmatera commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@rocky thanks for facing this. LGTM

@rocky
rocky merged commit 9a43827 into master Jul 24, 2026
18 checks passed
@rocky
rocky deleted the add-Association-atom branch July 24, 2026 10:31
@rocky

rocky commented Jul 24, 2026

Copy link
Copy Markdown
Member Author

@rocky thanks for facing this. LGTM

Now we can move on to putting Information into an association, which is what motivated this.

@mmatera

mmatera commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

I am curious: have you run some benchmarks to see it there was any performance improvement by handling associations with native dictionaries?

@rocky

rocky commented Jul 24, 2026

Copy link
Copy Markdown
Member Author

I am curious: have you run some benchmarks to see it there was any performance improvement by handling associations with native dictionaries?

Sadly, no, I haven't run any benchmarks.

@rocky

rocky commented Jul 24, 2026

Copy link
Copy Markdown
Member Author

Also, there are several Association commands that can now be easily implemented, such as AssociationTo, KeyMemberQ, KeySelect, KeyDropFrom, etc.

I should make an issue for all of that stuff.

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