types.Class.is_frozen
classReports whether this reference to the class was frozen with freeze().
Return value
true if the class is immutable, false otherwise.
Notes
Takes no arguments. The immutable flag lives on the reference, not on the class object: freeze(SomeClass) returns a new, frozen reference to the same class, but a variable that already held that class keeps pointing at an unfrozen reference, and so does every copy made from it before the freeze. SomeClass.is_frozen() stays false unless the variable itself is reassigned to the frozen result, as in SomeClass = freeze(SomeClass).
A frozen class rejects newmember and rawset with trying to modify immutable 'class' and Cannot modify immutable object respectively (the two native paths report it with different text). This is a stronger block than lock(): a locked-but-unfrozen class still accepts new static and function members, while a frozen one rejects every mutation.
Example
class Foo { x = 1 }
println("Foo.is_frozen() before freeze =", Foo.is_frozen())
let frozenFoo = freeze(Foo)
println("frozenFoo.is_frozen() =", frozenFoo.is_frozen())
println("Foo.is_frozen() after freeze =", Foo.is_frozen())Foo.is_frozen() before freeze = false
frozenFoo.is_frozen() = true
Foo.is_frozen() after freeze = falseSee also
lock | Locks the class immediately, without creating an instance. |
newmember | Adds a member to the class, optionally as a static one. |
rawset | Creates or replaces a member of the class, and unlike newmember, wires key and value to the roles their names suggest. |
freeze | Returns a reference to obj with the immutable flag set. |
| class | class index |