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). lock() also rejects every mutation, but through every reference and only from the moment the class locks; a frozen reference rejects them on a class that is not locked yet too.
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 |