Unique identification for value types
A subclass of
ObjAt that should be used to indicate that a class produces objects that are value types (in other words: are immutable after they have been initialized.
my = a => 42; # mutable Hashsay .WHICH; # OUTPUT: «ObjAt.new("Hash|1402...888")␤»my is Map = a => 42; # immutable Mapsay .WHICH; # OUTPUT: «ValueObjAt.new("Map|AAF...09F61F")␤»
If you create a class that should be considered a value type, you should add a
WHICH method to that class that returns a
ValueObjAt object, for instance:
Note that it is customary to always start the identifying string with the name of the object, followed by a "|". This to prevent confusion with other classes that may generate similar string values: the name of the class should then be enough of a differentiator to prevent collisions.
ValueObjAt inherits from class ObjAt, which provides the following routines:
multi sub infix:<eqv>(ObjAt , ObjAt )
Returns True if the two ObjAt are the same, that is, if the object they identify is the same.
my = [2,3,1];my := ;say .WHICH eqv .WHICH; # OUTPUT: «True␤»