- DESCRIPTION
- The root class of all objects. All classes are implicitly or explicitly extended directly or indirectly from class Object.
- CLASS_METHODS
- create_duplicate(Object existing).Object
- METHODS
- hash_code().Int32
- create_duplicate().Object
- Should create a duplicate of this object such that obj1.op==(obj1.create_duplicate) return true.
- The command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method.
- For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'.
- This default implementation throws an UnsupportedMethodError.
- to_String().String
- op==(Object other).Logical {multimethod}
- Returns true if this object is equivalant to another.
- The compiler converts 'obj1 == obj2' into 'obj1.op==(obj2)' and 'obj1 != obj2' into 'not obj1.op==(obj2)'.
- Implementations of op==() must maintain the following general contract between op==(), op<>(), and hash_code().
- Contract:
-
if (obj1.op==(obj2))
obj1.op<>(obj2) == eq
obj1.hash_code == obj2.hash_code
else
obj1.op<>(obj2) != eq
endIf
Note that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code.
- This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
- op==() is a multimethod, meaning that if there are versions op==(Alpha a) and op==(Beta b) and they are called with an object of unknown type, the most appropriate version method will be invoked. Make your own op==() definitions multimethods as well to propagate this behavior.
- op<>(Object other).Logical {multimethod}
- This method is used for ordering (quantitative) comparisons between this object and another.
- Returns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another.
- The compiler converts:
'obj1 < obj2' -> 'obj1.op<>(obj2) == lt'
'obj1 > obj2' -> 'obj1.op<>(obj2) == gt'
'obj1 <= obj2' -> 'obj1.op<>(obj2) != gt'
'obj1 >= obj2' -> 'obj1.op<>(obj2) != lt'
Implementations of op<>() must maintain the following general contract between op==(), op<>(), and hash_code().
- Contract:
-
if (obj1.op<>(obj2) == eq)
obj1.op==(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.op==(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code.
- op<>() is a multimethod, meaning that if there are versions op<>(Alpha a) and op==(Beta b) and they are called with an object of unknown type, the most appropriate version method will be invoked. Make your own op<>() definitions multimethods as well to propagate this behavior.
- This default implementation throws an UnsupportedMethodError.
- type_name().String : native
- runtime_type().RuntimeType : native
- runtime_properties().RuntimeProperties
- Part of Slag's introspection model, this method returns an object that models the properties of this object.
- Example:
# Print out the values of any strings that an object contains.
local Object obj = ...
local RuntimeType type_string("String")
forEach (p in obj.runtime_properties)
if (p.runtime_type == type_string)
println( "String property $ contains: $" (p.name,p.as_Object) )
endIf
endForEach
# Add one to an object's "x" property if it exists (assumed Int32).
local var p = obj.runtime_properties["x"]
if (p?) p.as_Int32 = p.as_Int32 + 1 # or: ++p.as_Int32
- runtime_methods().RuntimeMethods
|