Compounds - brombres/Rogue GitHub Wiki
Syntax
class Counter( value=1:Int32, limit=10:Int32, ... ) [compound]
GLOBAL METHODS
method create( alternate-constructor-1 )->Counter
return Counter( ... )
method create( alternate-constructor-2 )->Counter
return Counter( ... )
PROPERTIES
additional-property : SomeType
...
METHODS
method advance [mutating]
if (value < limit) ++value
method is_finished->Logical
return (value == limit)
endClass
Description
- A compound defines a datatype that is pass-by-value instead of the typical pass-by-reference.
- A compound class creates a compound whereas a standard object class creates an object.
- Compounds are stack-based allocations that do not require any memory management.
- Constructors must be global factory methods (
create(...)) rather than initializers (init(...)) typically used with objects.
- All compound methods are read-only or immutable by default.
- A compound method can change compound properties if it has the
[mutable] attribute.
- Mutable compound methods can only be called directly on a compound variable (a property or local); they cannot be called on method return values.