
On 21Jan2022 12:22, Ben Rudiak-Gould <benrudiak@gmail.com> wrote:
There seem to be two different reasons people want a generic freeze syntax:
1. Making a hashable copy of an arbitrary object
2. Avoiding O(n) rebuilding of literals on every use (a constant for bytecode, as you put it)
The purpose of the operator (aside from genericity) was to enable expression inspection by the compiler so that it can do for "|{1,2,3}|" what it already does for "x in {1,2,3}". The "generic" side to the operator approach was to provide a "freeze" protocol one could use for generic objects.
In both 1 and 2, not only the object but all of its children need to be immutable.
This is not strictly true. My own notion was a "shallow" freeze, not a recursive freeze. For hashability, provided the hash and equality tests only consider the frozen components, there's no need for a deep freeze - just a frezze of the relevant aspects. Cheers, Cameron Simpson <cs@cskk.id.au>