Skip to content

Add freeze() builtin for deep immutability (#78)#480

Merged
geseq merged 1 commit into
d5:masterfrom
ganehag:feature/freeze
Apr 29, 2026
Merged

Add freeze() builtin for deep immutability (#78)#480
geseq merged 1 commit into
d5:masterfrom
ganehag:feature/freeze

Conversation

@ganehag

@ganehag ganehag commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

freeze(x) recursively converts Arrays to ImmutableArrays and Maps to ImmutableMaps. Already-immutable values with no mutable children are returned as the same pointer (zero allocation). A memo table prevents infinite recursion on self-referential structures.

Primitives, strings, bytes, functions and errors pass through unchanged.

Closes the planned item from docs/freeze-builtin.md.

freeze(x) recursively converts Arrays to ImmutableArrays and Maps to
ImmutableMaps. Already-immutable values with no mutable children are
returned as the same pointer (zero allocation). A memo table prevents
infinite recursion on self-referential structures.

Primitives, strings, bytes, functions and errors pass through unchanged.

Closes the planned item from docs/freeze-builtin.md.

@geseq geseq left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Thanks for the PR!

@geseq geseq merged commit 8daf696 into d5:master Apr 29, 2026
1 check 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.

2 participants