ID:2821779
 
Applies to:
Status: Open

Issue hasn't been assigned a status value.
A great way to lower memory cost when reusing a list across thousands of atoms is to keep it in one place, and reference that everywhere. However, this opens up the potential for a developer to accidentally mutate the list, which will mess up everything else.

It would be nice to be able to freeze a list, causing a runtime error if the list was mutated.

This could just be a shallow freeze, and doesn't need to try to do crazy stuff like make the atoms inside immutable or whatever, just block insert/remove/update/etc. If a function was provided to check if a list is frozen, a developer could also make their own deep freeze proc.

Ideally there would be no way to "thaw" a list.

Prior art:

Object.freeze, Object.isFrozen in JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/ Reference/Global_Objects/Object/freeze

table.freeze, table.isfrozen in Luau: https://luau-lang.org/library#table-library
Even better: if this is caught by the compiler in trivial cases
There is of course already the /static|global/ sugar to use on a given datum's members to provide the reuse part. /const/ gives us immutable static members, but only if they are simple.

Allowing /const/ on lists that only contain numbers, text, and paths at compile time and flagging them as immutable, to throw if an attempt is made, sounds like a big QOL bonus to me.
That would not work for any of our use cases if it limited what was inside the list, and was only available at compile time. We only need a shallow freeze and potentially a way to see if a list is frozen, like several other languages provide.
Adding this functionality would worsen the performance of lists across the board, which is untenable.