Internal use.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
next : PatternMatcher terms : PatternMatcher[] |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( PatternMatcher p1, PatternMatcher p2, PatternMatcher p3 )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init() init( PatternMatcher p1, PatternMatcher p2 ) match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean
Overridden in CharRangePatternMatcher
to_String().Stringtype_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Internal use.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
max_count : Int32 min_count : Int32 next : PatternMatcher |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( [Int32 min_count], [Int32 max_count] )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean
Overridden in CharRangePatternMatcher
to_String().Stringtype_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Internal use.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
max_count : Int32 min_count : Int32 next : PatternMatcher term : PatternMatcher |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
find_matches( PatternMatchInfo state ).BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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'). hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( PatternMatcher term, [Int32 min_count], [Int32 max_count] )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean
Overridden in CharRangePatternMatcher
to_String().Stringtype_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Primarily for internal use - in most cases use ArrayList instead.
Array is a placeholder type. Arrays are actually implemented in the runtime implementation; calls to array methods are intercepted by the program loader and translated into array-related opcodes.
The exception to this is when a call is made to an array using a reference of aspect types Readable or IndexedData - the loader is unable to intercept. However, the Slag-side implementation of each array simply calls itself, and *that* call *is* intercepted by the compiler.
To get an array in Slag you must be explicit, e.g. "Array<<Int32>>(20)". Convenience notation (such as Array[20]) generates ArrayLists instead.
Arrays are not covariant as they are in Java. An Array<<String>> counts as an Object but not as an Array<<Object>>.
Arrays may be extended or augmented but no new object variables may be added.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
clear( Int32 first_index, Int32 last_index )
Clears all the elements in this array between the two indices.
compare_to( Object other ).TernaryUsing this method to clear elements at the end of an arraylist allows the runtime to limit the number of reference array elements it searches through during a data collection. Technical note: the runtime tracks the furthest position that a non-null reference array element could possibly be at after various calls to clear() and set().
This method is used for ordering (quantitative) comparisons
between this object and another.
contains( DataType value ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Returns "true" if this data contains the given value.
copy_elements( ArrayType src_array, Int32 src_index, Int32 dest_index, Int32 number )
Copies 'number' elements from another array (starting at
element 'src_index') into this one (starting at element
'dest_index').
count().Int32Elements may be copied within overlapping regions of the same array.
Returns the count of how many elements are in this array.
create_duplicate().Array<<DataType>>
Creates a duplicate of this array when the "duplicate(array)"
command is given. If the array element type is a reference
type, the new array contains a copy of the same references
to the same objects - the objects themeselves are not
duplicated.
create_reader().Reader<<DataType>>
Returns a reader that can be used to read() this data one
element at a time.
end( Int32 from_end ).DataType
Equivalent to get( (count-1) + from_end ).
equals( DataType value ).Boolean[]For example, end(0) is equivalent to last() and end(-1) is equivalent to get(count-2).
Returns a list of Boolean values where each value true if
the corresponding element of this indexed data equals()
the given value.
equals( Readable<<DataType>> other ).Boolean
Returns true if each element of this data equals() each
corresponding element from in 'other'.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
first().DataTypeThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the first element of this data. This convenience
method is equivalent to get(0).
format( String prefix, String prepeat, String suffix ).String
Converts this list into a string using the following format:
format( String str_format, [String repeater_chars] ).Stringprefix + $0 + [prepeat + $N]* + suffixwhere "$0" is the first element and $N is every other element. Example:
local Int32[] nums = 11..15
println( nums.to_String("[", "+", "]") )
# prints: [11+12+13+14+15]
Easier convenience method to accomplish to_String(prefix,prepeat,suffix).
from( Range<<Int32>> range ).Reader<<DataType>>Breaks down a simple format like this:
{$[ or $]}
Into a prefix="{", prepeat=" or ", suffix="}".
Normally "[]" brackets are used to denote the repeater portion, but this may be specified otherwise. Example: local Int32[] nums = 11..15 println( nums.to_String( "[$:+$:]", ":" ) # prints: [11+12+13+14+15]
Returns a reader that can be used to read() this data one
element at a time from the given starting index up to and
including the ending index.
from( Int32 starting_index ).Reader<<DataType>>
Returns a reader that can be used to read() this data one
element at a time with the given 'starting_index'.
get( Int32 index ).DataType
Retieves the element at the zero-based 'index'.
get( Readable<<Boolean>> flags ).DataType[]Requires: 0 <= index < count
Returns a new list containing the subset of elements
of which each of the corresponding 'flags' is true.
get( Readable<<Int32>> indices ).DataType[]Example:
local Int32[] nums = {1..10}
println( nums[nums % 2 == 0] )
#prints: {2,4,6,8,10}
Gets the element at each of the given zero-based 'indices'.
hash_code().Int32Example:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
index_of( DataType value, [Int32 starting_index] ).Int32Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns the first index that the given value occurs at
starting at index 0 by default. (-1) is returned if
'value' is not found.
indices().Range<<Int32>>
Returns this data's range of indices (0..count-1).
init( Int32 size )
Sets up this array to contain the given number of elements.
is_empty().Boolean
Returns true if count == 0.
is_not_empty().Boolean
Returns true if count > 0.
last().DataType
Returns the last element of this data. This convenience
method is equivalent to get(count-1).
last_index_of( DataType value, [Int32 starting_index] ).Int32
Returns the last index that the given value occurs at
starting at index (count-1) by default. (-1) is
returned if 'value' is not found.
modification_count().Int32
Returns a counter representing the number of times items
has been added to or removed. Used by readers to detect
concurrent list modification errors. For example, when an inner
method removes an item from a list the modification counter
is incremented. An outer "forEach" loop will detect that the
count is different from its original value and throw a
ConcurrentListModification error.
random().DataType
Returns an element of this data at random.
reverse()
Reverses the order of the elements in this data.
reverse_indices().Range<<Int32>>
Returns this data's range of indices reversed (count-1 downTo 0).
reverse_order().Reader<<DataType>>Example:
local Int32[] nums = {5..7}
forEach (i in nums.reverse_indices) println( i )
#prints: 2 | 1 | 0
Returns a reader that can be used to read() this data one
element at a time from the last element (N-1) to the first (0).
reversed().IndexedData<<DataType>>
Returns an list containing the elements of this data
in reverse order.
set( Int32 index, DataType value )
Sets the element at the zero-based 'index' to the new 'value'.
set( Readable<<Boolean>> flags, DataType value )Requires: 0 <= index < count
Starting at index 0, sets each element to the given 'value'
if the corresponding 'element_flags' are true.
set( Readable<<Int32>> indices, Readable<<DataType>> values )Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = 0
println( nums ) #prints: {0,2,0,4,0}
Sets the element at each of the given 'indices' to each of
the corresponding 'values'.
set( Readable<<Boolean>> element_flags, Readable<<DataType>> values )Requires: The number of indices == the number of values.Example:
local Int32[] nums = {1..5}
nums[0..4 step 2] = {7,8,9}
println( nums )
#prints: {7,2,8,4,9}
Starting at index 0, sets each element to the next of the
given 'values' if the corresponding 'element_flags' are true.
set( Readable<<Int32>> indices, DataType value )Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = -nums
println( nums ) #prints: {-1,2,-3,4,-5}
Sets the element at each of the given 'indices' to the given
'value'.
shuffle()Example:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Swaps every element of this data with another element at a
randomly-chosen position.
shuffled().IndexedData<<DataType>>
Returns a shuffled copy of this data.
subset( Int32 first_index, Int32 last_index ).ArrayList<<DataType>>
Returns the subset of this data between indices
[first_index,last_index] inclusive.
swap( Int32 index_a, Int32 index_b )
Swaps the value at 'index_a' with the one at 'index_b'.
to_List().DataType[]Requires: 0 <= index_a < count 0 <= index_b < countInvariant: this[index_a] = old[index_b] this[index_b] = old[index_a]
Converts this data into a list.
to_String().String
Returns a string representation of this data.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
The most common "collection" type in Slag, an ArrayList is an indexable list of items implemented using arrays.
An array list has 'count' and 'capacity'. Capacity is how many elements an arraylist can store before it has to create a larger backing array. Count is how many elements of the current array are currently in use. When 'count' reaches 'capacity', the next add() operation causes the backing array to be doubled in size.
An arraylist starts out at capacity 10, count 0 by default.
When you use "array notation" in Slag it creates arraylists. The following convenience conversions are performed:
# Create an empty list with 10 capacity
Int32[] nums(10) # 10 capacity
-> List<<Int32>> nums = ArrayList<<Int32>>(10)
# Create a list of 10 zero/null values
Int32[] nums = Int32[10]
-> List<<Int32>> nums = ArrayList<<Int32>>( 10, 0 )
# Create a list with the numbers 1 to 3
Int32[] nums = { 1, 2, 3 }
-> List<<Int32>> nums = ...
ArrayList<<Int32>>().add(1).add(2).add(3)
Invariant:
count >= 0 capacity >= count data.count == capacity
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
promote( DataType value ).DataType[]Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise
When there is an operation of the form
"DataType + List<<DataType>>" (where DataType is a
primitive or compound), the compiler calls this method to
promote the left-hand side operand to an object.
|
| Object Variables |
|---|
|
counter : Int32
The position to add the next item - also equivalent to the
used item count.
data : Array<<DataType>>
The backing array for this arraylist.
modification_count : Int32 |
| Object Methods |
|---|
|
add( DataType value, Int32 after_index ).List<<DataType>>
Inserts 'value' after the given index.
add( Readable<<DataType>> source ).List<<DataType>>Returns: A reference to this list for call-chaining.Requires: after_index >= -1 and after_index < countInvariant: new.count == old.count + 1 new[after_index+1] == value
Adds each item from the Readable source to this list.
add( DataType value ).ArrayList<<DataType>>Returns a reference to this list for call-chaining.
Adds the given 'value' to the end of this list.
capacity().Int32Returns a reference to this list for call chaining. Invariant: count = old.count + 1 get[count-1] == value
Returns how many values this list can store before its backing
array must be doubled in size.
clear()
Removes all elements from this list. The capacity
is unchanged.
compare_to( Readable<<DataType>> values ).Ternary[]Invariant: new.count == 0 new.capacity == old.capacity
Compares each of this list's values to each corresponding
given value and returns a list of Ternary 'gt', 'lt', and
'eq' values.
compare_to( Object other ).TernaryOnly implemented for numerical List types.
This method is used for ordering (quantitative) comparisons
between this object and another.
compare_to( DataType value ).Ternary[]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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Compares each of this list's values to the given value and
returns a list of Ternary 'gt', 'lt', and 'eq' values.
contains( DataType value ).BooleanOnly implemented for numerical List types.
Returns "true" if this data contains the given value.
count().Int32
Returns how many values there are in this list.
create_duplicate().ArrayList<<DataType>>
Creates a duplicate of this list when the "duplicate(list)"
command is given. If the list element type is a reference
type, the new list contains a copy of the same references
to the same objects - the objects themeselves are not
duplicated.
create_reader().Reader<<DataType>>Results: A duplicate list such that "all(this is result)" equals true.
Returns a reader that can be used to read() this data one
element at a time.
discard( Int32 first_index, [Int32 last_index] )
Removes the elements in the specified range. Does not return
the list of removed elements like remove() does. If only
the 'first' parameter is given, elements from 'first' to the
end of the list are discarded.
discard( Range<<Int32>> range )'first' and 'last' are clipped to be a valid range.
Removes elements in the specified range.
end( Int32 from_end ).DataTypeRequires: range.is_contiguous_ascending
Equivalent to get( (count-1) + from_end ).
ensure_capacity( Int32 min_capacity )For example, end(0) is equivalent to last() and end(-1) is equivalent to get(count-2).
Effects that this list has a capacity of at least
'min_capacity'. If it has a lower capacity, the backing
array is reallocated to have the necessary capacity.
equals( Readable<<DataType>> other ).Boolean
Returns true if each element of this data equals() each
corresponding element from in 'other'.
equals( DataType value ).Boolean[]
Returns a list of Boolean values where each value true if
the corresponding element of this indexed data equals()
the given value.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
expand_to_capacity().ArrayList<<DataType>>The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Effectively adds enough null/zero values to this arraylist so
that the count matches the capacity. Technically the backing
array is maintained with null/zero values and so a counter
is adjusted.
first().DataTypeReturns: A reference to this list for call chaining.Invariant: count == capacity
Returns the first element of this data. This convenience
method is equivalent to get(0).
format( String prefix, String prepeat, String suffix ).String
Converts this list into a string using the following format:
format( String str_format, [String repeater_chars] ).Stringprefix + $0 + [prepeat + $N]* + suffixwhere "$0" is the first element and $N is every other element. Example:
local Int32[] nums = 11..15
println( nums.to_String("[", "+", "]") )
# prints: [11+12+13+14+15]
Easier convenience method to accomplish to_String(prefix,prepeat,suffix).
from( Int32 starting_index ).Reader<<DataType>>Breaks down a simple format like this:
{$[ or $]}
Into a prefix="{", prepeat=" or ", suffix="}".
Normally "[]" brackets are used to denote the repeater portion, but this may be specified otherwise. Example: local Int32[] nums = 11..15 println( nums.to_String( "[$:+$:]", ":" ) # prints: [11+12+13+14+15]
Returns a reader that can be used to read() this data one
element at a time with the given 'starting_index'.
from( Range<<Int32>> range ).Reader<<DataType>>
Returns a reader that can be used to read() this data one
element at a time from the given starting index up to and
including the ending index.
get( Readable<<Int32>> indices ).DataType[]
Gets the element at each of the given zero-based 'indices'.
get( Int32 index ).DataTypeExample:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Returns the element at the given zero-based index.
get( Readable<<Boolean>> flags ).DataType[]Requires: 0 <= index and index < count
Returns a new list containing the subset of elements
of which each of the corresponding 'flags' is true.
hash_code().Int32Example:
local Int32[] nums = {1..10}
println( nums[nums % 2 == 0] )
#prints: {2,4,6,8,10}
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
index_of( DataType value, [Int32 starting_index] ).Int32Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns the first index that the given value occurs at
starting at index 0 by default. (-1) is returned if
'value' is not found.
indices().Range<<Int32>>
Returns this data's range of indices (0..count-1).
init( Readable<<DataType>> readable )
Initializes this list to contain all the items from the
'readable' data source.
init( Int32 initial_capacity, DataType content )
Creates an array list full of 'initial_capacity' duplicates of
the given 'content'.
init()
Creates an empty arraylist of capacity 10.
init( Int32 initial_capacity )
Creates an empty arraylist with a specified initial capacity.
insert( DataType value, [Int32 before_index] ).ArrayList<<DataType>>
Inserts the 'value' in front of 'before_index'. Elements
at 'begin_index' and higher are shifted over by one.
insert( IndexedData<<DataType>> seq, [Int32 before_index] ).ArrayList<<DataType>>Returns: A reference to this list for call chaining.Requires: 0 <= before_index and before_index <= countInvariant: this[before_index] = value this[before_index+1] = old[before_index] count = old.count + 1
Inserts all the given values in front of 'before_index'. Elements
at 'begin_index' and higher are shifted over by one.
is_empty().BooleanReturns: A reference to this list for call chaining.Requires: 0 <= before_index and before_index <= countInvariant: this[before_index] = value this[before_index+seq.count] = old[before_index] count = old.count + seq.count
Returns true if count == 0.
is_not_empty().Boolean
Returns true if count > 0.
last().DataType
Returns the last element of this data. This convenience
method is equivalent to get(count-1).
last_index_of( DataType value, [Int32 starting_index] ).Int32
Returns the last index that the given value occurs at
starting at index (count-1) by default. (-1) is
returned if 'value' is not found.
modification_count().Int32
Returns a counter representing the number of times items
has been added to or removed. Used by readers to detect
concurrent list modification errors. For example, when an inner
method removes an item from a list the modification counter
is incremented. An outer "forEach" loop will detect that the
count is different from its original value and throw a
ConcurrentListModification error.
op!().DataType[]
Returns a list containing the logical complement of each
value in this list.
op%( Readable<<DataType>> values ).DataType[]Only implemented for integer and Boolean List types.
Returns a list of the remainders of each of this list's
values divided by each of the corresponding given values.
op%( DataType value ).DataType[]Only implemented for numerical List types.
Returns a list of the remainders of each of this list's
values divided by the given value.
op&( Readable<<DataType>> values ).DataType[]Only implemented for numerical List types.
Performs a bitwise 'and' operation between each
of this list's values and each corresponding given value
and returns a list of results.
op&( DataType value ).DataType[]Only implemented for integer and Boolean List types.
Performs a bitwise 'and' operation between each
of this list's values and the given value and returns
a list of results.
op*( Readable<<DataType>> values ).DataType[]Only implemented for integer and Boolean List types.
Multiplies each given value by each of this list's
corresponding values and returns a list of the results.
op*( DataType value ).DataType[]Only implemented for numerical List types.
Multiplies the given value by each of this list's values and
returns a list of the results.
op+( Readable<<DataType>> values ).DataType[]Only implemented for numerical List types.
Adds each given value to each of this list's corresponding
values and returns a list of the results.
op+( DataType value ).DataType[]Only implemented for numerical List types.
Adds the given value to each of this list's values and
returns a list of the results.
op-().DataType[]Only implemented for numerical List types.
Returns a list containing the negative of each value in this
list.
op-( DataType value ).DataType[]Only implemented for numerical List types.
Subtracts the given value from each of this list's values and
returns a list of the results.
op-( Readable<<DataType>> values ).DataType[]Only implemented for numerical List types.
Subtracts each given value from each of this list's
corresponding values and returns a list of the results.
op/( Readable<<DataType>> values ).DataType[]Only implemented for numerical List types.
Divides each of this list's values by each corresponding
given value and returns a list of the results.
op/( DataType value ).DataType[]Only implemented for numerical List types.
Divides each of this list's values by the given value and
returns a list of the results.
op^( DataType value ).DataType[]Only implemented for numerical List types.
Raises each of this list's values to the power of the given
value and returns a list of the results.
op^( Readable<<DataType>> values ).DataType[]Only implemented for numerical List types.
Raises each of this list's values to the power of each
corresponding given value and returns a list of the results.
op|( DataType value ).DataType[]Only implemented for numerical List types.
Performs a bitwise 'or' operation between each
of this list's values and the given value and returns
a list of results.
op|( Readable<<DataType>> values ).DataType[]Only implemented for integer and Boolean List types.
Performs a bitwise 'or' operation between each
of this list's values and each corresponding given value
and returns a list of results.
op~( DataType value ).DataType[]Only implemented for integer and Boolean List types.
Performs a bitwise 'xor' operation between each
of this list's values and the given value and returns
a list of results.
op~( Readable<<DataType>> values ).DataType[]Only implemented for integer and Boolean List types.
Performs a bitwise 'xor' operation between each
of this list's values and each corresponding given value
and returns a list of results.
product().DataTypeOnly implemented for integer and Boolean List types.
Returns the product of all the values contained in this
list-adaptable object.
random().DataTypeOnly implemented for numerical list types.
Returns an element of this data at random.
remove( Range<<Int32>> range ).DataType[]
Removes and returns the elements in the specified range.
See discard() for a variant that's optimal when you don't
need the return value.
remove( DataType value ).BooleanRequires: range.is_contiguous_ascending
Calls remove_value(value). Only available for non-numerical
lists - see note in remove_value().
remove( Int32 first_index, Int32 last_index ).DataType[]
Removes and returns the elements in the specified range.
remove( Int32 index ).DataType'first' and 'last' are clipped to be a valid range. Returns: The list of elements from old[first] through old[last].
Removes and returns the element at position 'index'. All
elements higher than 'index' are shifted down by one spot
and the list count is decremented.
remove_first().DataTypeReturns: old[index]Requires: 0 <= index and index < countInvariant: new[index] = old[index+1]
Equivalent to:
remove_last().DataTypelist.remove(0)
Equivalent to:
remove_value( DataType value ).Booleanlist.remove(list.count-1)
Removes the first occurrence of 'value' from the list.
reverse()Returns: "true" if an occurrence of 'value' was found and removed, or "false" if it was not found.Technical note: this method can't be named remove() because in an Int32[] list, remove(index) and remove(value) would have the same signature.
Reverses the order of the elements in this data.
reverse_indices().Range<<Int32>>
Returns this data's range of indices reversed (count-1 downTo 0).
reverse_order().Reader<<DataType>>Example:
local Int32[] nums = {5..7}
forEach (i in nums.reverse_indices) println( i )
#prints: 2 | 1 | 0
Returns a reader that can be used to read() this data one
element at a time from the last element (N-1) to the first (0).
reversed().IndexedData<<DataType>>
Returns an list containing the elements of this data
in reverse order.
set( Readable<<Int32>> indices, Readable<<DataType>> values )
Sets the element at each of the given 'indices' to each of
the corresponding 'values'.
set( Readable<<Boolean>> element_flags, Readable<<DataType>> values )Requires: The number of indices == the number of values.Example:
local Int32[] nums = {1..5}
nums[0..4 step 2] = {7,8,9}
println( nums )
#prints: {7,2,8,4,9}
Starting at index 0, sets each element to the next of the
given 'values' if the corresponding 'element_flags' are true.
set( Readable<<Boolean>> flags, DataType value )Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = -nums
println( nums ) #prints: {-1,2,-3,4,-5}
Starting at index 0, sets each element to the given 'value'
if the corresponding 'element_flags' are true.
set( Int32 index, DataType value )Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = 0
println( nums ) #prints: {0,2,0,4,0}
Sets the element at the given zero-based index.
set( Readable<<Int32>> indices, DataType value )Requires: 0 <= index and index < count
Sets the element at each of the given 'indices' to the given
'value'.
shuffle()Example:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Swaps every element of this data with another element at a
randomly-chosen position.
shuffled().IndexedData<<DataType>>
Returns a shuffled copy of this data.
sort( [SORT order] )
Sorts this list in place using a HeapSort.
'order' is SORT.ascending by default.
sorted( [SORT order] ).List<<String>>Only implemented for numerical and String lists. To enable it for lists of other types (say, Event), add this augment:
augment List<<Event>>
METHODS
method sort( SORT order=SORT.ascending ):
HeapSort<<DataType>>.sort( this, order )
endAugment
Returns an list containing the elements of this data
sorted into order. Only implemented for numerical and
String lists.
subset( Int32 first_index, Int32 last_index ).ArrayList<<DataType>>
Returns the subset of this data between indices
[first_index,last_index] inclusive.
sum().DataType
Returns the sum of all the values contained in this
list-adaptable object.
swap( Int32 index_a, Int32 index_b )Only implemented for numerical list types.
Swaps the value at 'index_a' with the one at 'index_b'.
to_List().DataType[]Requires: 0 <= index_a < count 0 <= index_b < countInvariant: this[index_a] = old[index_b] this[index_b] = old[index_a]
Satisifies the ListAdaptable aspect of the IndexedData aspect
by returning this list with no modifications.
to_String().String
Returns:
trim_to_count().ArrayList<<DataType>>A String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Resizes the backing array to exactly fit the values currently
stored in this list. Only recommended when memory usage is
a concern and you won't be adding additional elements in the
near future.
type_name().StringReturns: A reference to this list for call chaining.Invariant: capacity == count
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Placeholder class that provides a common base type for all Array<<DataType>> classes.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
clear( Int32 first_index, Int32 last_index )
Clears all the elements in this array between the two indices.
compare_to( Object other ).TernaryUsing this method to clear elements at the end of an arraylist allows the runtime to limit the number of reference array elements it searches through during a data collection. Technical note: the runtime tracks the furthest position that a non-null reference array element could possibly be at after various calls to clear() and set().
This method is used for ordering (quantitative) comparisons
between this object and another.
copy_elements( ArrayType src_array, Int32 src_index, Int32 dest_index, Int32 number )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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Copies 'number' elements from another array (starting at
element 'src_index') into this one (starting at element
'dest_index').
count().Int32Elements may be copied within overlapping regions of the same array.
Returns the count of how many elements are in this array.
create_duplicate().Object
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
to_String().StringHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Internal use.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
next : PatternMatcher tag_group_index : Int32 |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Int32 tag_group_index )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean
Overridden in CharRangePatternMatcher
to_String().Stringtype_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Allows integers of any size to be represented and manipulated. BigInt operations are significantly slower than operations on primitive Int32/Int64 types so BigInt objects should only be used when you require integers with more than 64 bits.
BigInt objects are immutable; operations produce new BigInteger objects as side effects instead of altering operands.
BigInt numbers are modeled using sign-magnitude; they are not 2's complement and the sign cannot be directly changed through a bitwise operation (only incidentally, as when a negative number is AND'd with zero to produce a zero result).
BigInt values are stored as a series of unsigned 16-bit Char values. Their total bit size (in multiples of 16) is only what's necessary to represent a number's magnitude; you cannot, for instance, specify that a number has "1000 zero bits".
Similar to Java's BigInteger class.
Examples:
println( BigInt(123456) ^ BigInt("1000101",2) )
println( "2^100 = $" (BigInt(2) ^ 100) )
| Class Variables |
|---|
|
last_modulo : BigInt one : BigInt ten : BigInt ten_e144 : BigInt ten_e18 : BigInt ten_e36 : BigInt ten_e72 : BigInt values : BigInt[] zero : BigInt |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
init_class()Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise promote( Int64 n ).BigInt
Creates a BigInt object out of an Int64 value. If
'n' is 0..15 then a pre-defined BigInt object will
be returned instead.
|
| Object Variables |
|---|
|
data : ArrayList<<Char>> sign_flag : Int32 |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary compare_to( Int64 n ).Ternary compare_to( BigInt other ).Ternary create_duplicate().Object
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Int64 n ).BooleanThe 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. equals( Object other ).Boolean equals( BigInt other ).Boolean hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init()Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init( BigInt other ) init( Int32 value ) init( Int64 value ) init( String value, [Int32 base] )
Initializes this BigInt to a value specified as a string
of digits in a given base. 'base' can be 2, 10, or 16.
internal_to_Int64().Int64is_negative().Boolean is_valid_Int32().Boolean is_valid_Int64().Boolean is_zero().Boolean left_shifted( Int32 bits ).BigInt normalized().BigInt
Removes excess zero values on the most signficant end
and changes a negative zero to a positive zero.
op%( BigInt n ).BigIntop%( Int64 n ).BigInt op&( BigInt n ).BigInt op&( Int64 n ).BigInt op*( Int64 n ).BigInt op*( BigInt n ).BigInt op+( Int64 n ).BigInt op+( BigInt n ).BigInt op-( Int64 n ).BigInt op-().BigInt op-( BigInt n ).BigInt op/( Int64 n ).BigInt op/( BigInt n ).BigInt op^( BigInt n ).BigInt op^( Int64 n ).BigInt op|( BigInt n ).BigInt op|( Int64 n ).BigInt op~( BigInt n ).BigInt op~( Int64 n ).BigInt right_shifted( Int32 bits ).BigInt sign().Int32
Returns -1, 0, or 1.
to_Int32().Int32to_Int64().Int64 to_String( Int32 base ).String to_String().String type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Incorporate this aspect into enumerated types associated with Int32 values that define bit flags.
For example:
enum DIRECTION : BitFlags<<DIRECTION>>
CATEGORIES
north(1), east(2), south(4), west(8)
endEnum
...
local DIRECTION d = DIRECTION.north | DIRECTION.east
println( d == DIRECTION.north ) #prints: false
println( d.includes(DIRECTION.north) ) #prints: true
println( d ) #prints: north,east
println( d.flags ) #prints: 3
d &= !DIRECTION.north
println( d ) #prints: east
println( d == DIRECTION.east ) #prints: true
println( d.flags ) #prints: 2
| Class Variables |
|---|
|
default_next_flag : Int32 |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
flags : Int32 |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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. equals( Int32 other_flags ).Boolean equals( EnumType other ).Boolean hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
includes( EnumType other ).BooleanHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns "true" if this category contains any of the
bitflags from the 'other' category.
includes( Int32 other_flags ).Boolean
Returns "true" if this category contains any of the
bitflags from 'other_flags'.
init()init( Int32 flags ) init( EnumType existing ) op!().EnumType
Returns a new category that contains the inverse
of this category's bitflags.
op&( Int32 other_flags ).EnumType
Returns a new category that contains the intersection
of bitflags from this category and 'other_flags'.
op&( EnumType other ).EnumType
Returns a new category that contains the intersection
of bitflags from this category and the 'other' category.
op|( Int32 other_flags ).EnumType
Returns a new category that includes all the bitflags
from this category and 'other_flags'.
op|( EnumType other ).EnumType
Returns a new category that includes all the bitflags
from this category and the 'other' category.
to_String().String
Returns a string containing the names of all comma-separated
categories included in this category's bitflags.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A BitReader wraps an existing Reader<<Char>> and is able to read in 1-bit to 32-bit values at a time under normal operations. There are special method variants capable of reading in 64-bit values.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
bit_buffer : Int64
Internal use.
bit_count : Int32
Internal use.
src : Reader<<Char>>
The backing source of characters.
|
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
fill_buffer( Int32 to_n_bits )The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Internal use.
has_another().Boolean
Returns true if there are at least 8 bits left to read.
has_another( Int32 n_bits ).BooleanSee also: has_another(Int32)
Returns true if there are at least 'n_bits' left to read. 'n_bits'
must be 1..32.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Reader<<Char>> src )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this BitReader to read from the given character
reader.
init( Readable<<Char>> readable )
Initializes this BitReader to read from the given readable
character data.
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek( Int32 n_bits ).Int32
Returns the next 'n_bits' value that will be returned by
read(n_bits).
peek().Char
Returns the next 8-bit value that will be returned by read().
peek_bit().Int32
Returns the bit of input that will be returned by read_bit.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
read( Int32 n_bits ).Int32Readers that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Returns the next value of size 'n_bits', giving a value
between 0 and n_bits-1.
read().CharExample:
...
if (bits.peek == 0b01011000)
println( bits.read(3) ) # prints "2" (010)
println( bits.read(2) ) # prints "3" (11)
println( bits.read(3) ) # prints "0" (000)
endIf
Returns the next 8 bits as a Char.
read_Int64().Int64
Returns the next 64 bits as an Int64 assumed to be in
high-low byte order.
read_Int64_low_high().Int64
Returns the next 64 bits as an Int64 assumed to be in
low-high byte order.
read_bit().Int32
Returns the next bit of input.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
read_low_high( Int32 n_bits ).Int32
Returns the next n_bits as a value. n_bits must be 16 or 32
bits. This method assumes that the first 8 bits to be read
are the least significant byte of the answer (bits 7:1) and
the last 8 bits are the most significant byte of the number
(e.g. bits 31:24).
remaining().Int32Requires: n_bits == 16 or n_bits == 32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A BitWriter wraps an existing Writer<<Char>> and allows arbitrarily-sized values of 1-32 bits to be written. 64-bit values may also be written using a separate call.
The bits are buffered and groups of 8 at a time (single bytes) are written to the backing Char writer.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
bit_buffer : Int64
Internal use.
bit_count : Int32
Internal use.
dest : Writer<<Char>>
The backing character writer that a BitWriter outputs to.
|
| Object Methods |
|---|
|
capacity().Int32
Returns the minimum number of additional values that can
written with this writer, or (-1) for "unlimited".
clean_up()
Closes the writer. Base aspect Writer does not incorporate
the RequiresCleanup interface, but types for writers that do
this method will be called when there are no more references
to the object.
close()
Flushes and closes this BitWriter.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
flush()The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
If there are any buffered bits that haven't been written
to the backing writer yet, flush() writes out enough zero
bits to make eight total and writes the resulting byte
of information.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
holds_has_another().BooleanHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns true if at least one more value can be written with
write().
init( Writer<<Char>> dest )
Initializes this BitWriter to output to the given writer.
init( Writable<<Char>> writable )
Initializes this BitWriter to output to the given writable
object.
position( Int32 new_pos )
This optional property-write sets the zero-based write
position. It is up to the implementation to define how
repositioning works with gaps and what happens to data at a
later spot after a reposition to an earlier spot.
position().Int32Not all writers implement this property; those that don't will throw an UnsupportedMethodError when it's accessed.
This optional property-read returns the zero-based write
position. This will be "0" before anything is written, "1"
after a single write(), and so on.
skip( Int32 skip_count )Not all writers implement this property; those that don't will throw an UnsupportedMethodError when it's accessed.
This optional method repositions the writer to be
'skip_count' values further along.
to_String().StringIf a writer does not implement the 'position' property then an UnsupportedMethodError will be generated when skip() is called.
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
write( DataType value )Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String
Outputs 'value' in an implementation-specific way.
write( Int32 value, Int32 n_bits )Requires: holds_has_another == true
Writes 'value' in 'n_bits' using high-low byte order.
write( Char value )
Writes 'value' in 8 bits.
write_Int64( Int64 value )
Writes 'value' in 64 bits using high-low byte order.
write_Int64_low_high( Int64 value )
Writes 'value' in 64 bits using low-high byte order.
write_bit( Int32 b )
Writes 'b' (0 or 1) as a single bit.
write_low_high( Int32 value, Int32 n_bits )
Writes 'value' in 'n_bits' using low-high byte order.
'n_bits' must be 16 or 32. The least-significant byte
is written first and the most significant byte is written
last.
Requires: n_bits == 16 or n_bits == 32 |
Wraps an existing Reader<<FromType>> and casts each value to ToType.
Example:
local Real64[] nums = { 3.0, 3.5, 3.9, 4.0 }
forEach (n in CastReader<<Real64,Int32>>(nums)) println(n)
# prints: 3 3 3 4
Example:
# Read "data.txt" into a byte buffer.
local Byte[] buffer = CastReader<<Char,Byte>>(File("data.txt").create_reader).to_List
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
has_next : Boolean
If "true" then 'next' is a valid value.
next : OutputDataType
The next data that will be returned by peek() or read().
src : Reader<<InputDataType>>
The backing source of values for this reader.
|
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Readable<<InputDataType>> readable )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this BitReader to read from the given reader.
init( Reader<<InputDataType>> src )
Initializes this BitReader to read from the given readable
data.
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().OutputDataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
prep_next().BooleanReaders that don't implement this property will throw an UnsupportedMethodError when it's accessed. read().OutputDataType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
high_ch : Char low_ch : Char next : PatternMatcher |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Char low_ch, Char high_ch )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init( Char low_ch ) match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean to_String().String type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A range made up of ranges - each next value is obtained indirectly from a list of ranges. For example, {1..3,7..9} creates a CompositeRange object whose reader would return the values {1,2,3,7,8,9}.
This is relied on by the compiler internally; most programmers will not need to use it directly.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ranges : Range<<DataType>>[] |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
create_reader().Reader<<DataType>>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.
Returns a reader that can be used to read() this data one
element at a time.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Range<<DataType>>[] ranges )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
to_List().DataType[]
Converts this data into a list.
to_String().String
Returns a string representation of this CompositeRange.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Reader for a CompositeRange. Utilized by the Slag compiler; most programmers will not need to use this directly.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
cur_range : Reader<<DataType>> range_reader : Reader<<Range<<DataType>>>> |
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().CompositeRangeReader<<DataType>>Returns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Handles duplicating this iterator when "duplicate(iterator_obj)" is called.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Reader<<DataType>> cur_range, Reader<<Range<<DataType>>>> range_reader )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init( Reader<<Range<<DataType>>>> range_reader ) is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().DataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
prep_next()Readers that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Prepares the next value that will be used by peek() and
read(). As a composite range reader, this involves advancing
to the next range reader if the current range reader is
empty.
read().DataType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Thrown when a reader detects that other code has modified a list between one read and the next.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String message )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Stores the given error message.
init()
Default initializer.
to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A generator that returns the next value in the sequence with every read.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
next : DataType
The next number that will be returned from read().
step_size : DataType
The step size between consecutive numbers.
|
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().Counter<<DataType>>Returns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Handles duplicating this iterator when "duplicate(iterator_obj)" is called.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns true - standard generators always have another value.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( [DataType next], [DataType step_size] )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().DataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
read().DataTypeReaders that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Returns the next number and advances the counter.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( Int32 skip_count )
Discards 'skip_count' number of values that would otherwise
be returned from this generator.
to_List().DataType[]
Throws an UnsupportedMethodError.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Real64 wrapper compound that specifies an angle in degrees.
Degrees compounds may be used in trig operations such as sin() and cos().
Degrees-related methods in class Global
cos( Degrees deg ).Real64
new_Radians( Degrees deg ).Radians
op*( Real64 factor, Degrees deg ).Degrees
op+( Radians rad, Degrees deg ).Radians
op-( Radians rad, Degrees deg ).Radians
op-( Degrees deg1 ).Degrees
op/( Real64 factor, Degrees deg ).Degrees
print( Degrees deg )
println( Degrees deg )
random_Degrees().Degrees
sin( Degrees deg ).Real64
tan( Degrees deg ).Real64
to_Radians( Degrees deg ).Radians
to_String( Degrees deg ).String
| Composite Elements |
|---|
|
value : Real64 |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
to_String().StringHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String message )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this Error with the given message.
init()to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Internal use.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
next : PatternMatcher tag_group_index : Int32 |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Int32 tag_group_index )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean
Overridden in CharRangePatternMatcher
to_String().Stringtype_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A reader that steps through the enumeration categories between a start and an end value.
Created by Range<<DataType>> objects with an enumeration DataType.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
last_value : DataType next_value : DataType |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().EnumIterator<<DataType>>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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Handles duplicating this iterator when "duplicate(iterator_obj)" is called.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( DataType first_value, DataType last_value )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
peek().DataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
read().DataType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Base class for any 'enum'. See also "BitFlags"
NOTES The compiler converts:
enum FRUIT
CATEGORIES
apple, orange
...
endEnum
into:
class FRUIT : EnumeratedType<<FRUIT>>
CLASS_PROPERTIES
apple = set_up_def( FRUIT(), "apple" ) : FRUIT
orange = set_up_def( FRUIT(), "orange" ) : FRUIT
...
endClass
| Class Variables |
|---|
|
definitions : HashTable<<String,EnumType>>
Internal use - hashtable of names->categories.
values : EnumType[]
Internal use - a list of the category objects in this
enumeration.
|
| Class Methods |
|---|
|
by_name( String name ).EnumType
Returns the category object corresponding to the given string
name.
by_ordinal( Int32 ordinal ).EnumTypeContract:
FRUIT.by_name("banana") == FRUIT.banana
Returns the category object corresponding to the given
ordinal position.
create_duplicate( Object existing ).ObjectContract:
if (FRUIT.banana.ordinal == 2)
FRUIT.by_ordinal(2) == FRUIT.banana
endIf
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
includes( String name ).BooleanReturns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Returns "true" if the given name is a category of this
enumeration.
set_up_def( EnumType enum_def, String name ).EnumTypeExample:
FRUIT.includes("carrot") -> false
Internal use.
|
| Object Variables |
|---|
|
name : String
The name of this category. This is a string with the
the same as the enum categery.
ordinal : Int32Suit.spades.name == "spades"
The positional index value of this enumeration category,
corresponding to the order that the categories were
declared in (starting at zero).
enum Suit
CATEGORIES
spades, hearts, clubs, diamonds
endEnum
... Suit.spades.ordinal == 0 Suit.diamonds.ordinal == 3 |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
compare_to( EnumType other ).TernaryReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Returns the relative ordering (lt, eq, gt) of this enum's
ordinal versus the ordinal of the given enum.
create_duplicate().Object
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init()Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Default initializer.
next().EnumType
Returns the category that was defined after this one.
next_in_cycle().EnumTypeExample: Suit.spades.next == Suit.hearts Suit.diamonds.next is null
Like 'next' but wraps around from the last to the first.
previous().EnumTypeExample: Suit.spades.next_in_cycle == Suit.hearts Suit.diamonds.next_in_cycle == Suit.spades
Returns the category that was defined before this one.
previous_in_cycle().EnumTypeExample: Suit.spades.previous is null Suit.diamonds.previous == Suit.clubs
Like 'previous' but wraps around from the last to the first.
to_String().StringExample: Suit.spades.previous_in_cycle == Suit.diamonds Suit.diamonds.previous_in_cycle == Suit.clubs
Returns 'name'
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
All built-in exceptions are extended from this Error class.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String message )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Stores the given error message.
init()
Sets the error message to an empty string.
to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
The base class of all Error messages. An 'Exception' in Slag is equivalent to a RuntimeException in Java; there are no "checked exceptions" that *require* a try/catch block or a 'throws' clause. Most subclasses of Exception are derived from child class 'Error'.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String message )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Stores the given error message.
init()
Sets the error message to an empty string.
to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Represents a potential file in the operating system. A File object is created with a filepath; a file of that name may or may not exist yet.
A file object is both Readable and Writable as an input and output for characters.
Class File uses the following terminology:
filename
The name of a file without any location information.
path
The directory location where the file is stored.
filepath
A filename with path information.
Example:
# print every character in a file "test.txt"
forEach (ch in File("test.txt")) print( ch )
Example:
class RecursiveDirectoryListing
METHODS
method init:
# Recursively lists files starting in the current directory
list( "." )
method list( String filepath ):
local File file(filepath)
file.filepath = file.absolute_filepath
println( file.filepath )
if (file.is_directory)
forEach (entry in file.directory_listing)
list("$/$" (file.filepath,entry))
endForEach
endIf
endClass
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
native_absolute_filepath( String filepath ).StringReturns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Internal use.
native_directory_listing( String path, String[] contents )
Internal use.
native_is_directory( String filepath ).Boolean
Internal use.
|
| Object Variables |
|---|
|
filepath : String
The filepath of this file.
|
| Object Methods |
|---|
|
absolute_filepath().String
Returns the absolute filepath (path + file) of this file.
absolute_path().StringNote: If a filepath doesn't exist it will still be fleshed out with the current full path to allow this method to work with non-existent output files that will be created.
Returns the absolute path denoted by this File object.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
create_reader().FileReaderThe 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.
Creates and returns a character reader for this file which
opens the corresponding file in the operating system for
reading.
create_writer().PrintWriterIf the file doesn't exist or if there's some other error then a FileError exception is thrown.
Creates and returns a character writer for this file which
opens the corresponding file in the operating system for
writing.
directory_listing().String[]If an error occurs then a FileError exception is thrown.
Returns a list of filenames and directory names contained
within the directory represented by this File object. Throws
a FileError if this file does not denote a valid directory.
equals( Object other ).BooleanNote: the list of entries returned will not contain the current directory "." or the parent directory "..".
Returns true if this object is equivalant to another.
exists().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns whether or not this file already exists within the
operating system.
filename().String
Returns the filename (without path information) denoted by
this File.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String filepath )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this file object with the given filepath. No
operating system files are actually opened or created yet.
is_directory().Boolean
Returns "true" if the path of this file specifies a directory.
path().String
Returns the path denoted by this File object. This may be relative
or absolute depending on the string passed into the initializer.
At a minimum, the relative path "." will be returned.
to_List().DataType[]
Converts this Readable data into a list. Creates a reader
and fowards the call to it.
to_String().String
Returns the original filepath of this File object.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( [String message] )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this FileError with the given error message.
init()
Sets the error message to an empty string.
to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Reads one character at a time from a file.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
native_close( Int32 handle )Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Internal use.
native_file_size( Int32 handle ).Int32
Internal use.
native_open( String filename ).Int32
Internal use.
native_read( Int32 handle ).Int32
Internal use.
native_skip( Int32 handle, Int32 amount )
Internal use.
|
| Object Variables |
|---|
|
file_handle : Int32
The integer that the native layer uses to track this file.
next : Char
The next character that will be returned from read().
pos : Int32
Counts the number of characters that have been read.
total_size : Int32
The total number of characters in the file.
|
| Object Methods |
|---|
|
available().Int32
Returns the remaining number of characters in this file
since file readers don't block.
clean_up()
Called when there are no more references to this object;
closes the file.
close()
Closes this file; no more data may be read from this reader.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String filename )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Opens the given file and preps this reader to read it.
is_exhausted().BooleanIf the file doesn't exist or if there are other problems then a FileError will be thrown.
Returns "true" if this reader does not have another value
or "false" if it does.
peek().Char
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
Sets this position of this file. File readers can only be
repositioned further on in the file.
position().Int32
Returns the position of this file - equivalent to the
number of characters read so far.
read().Char
Returns the next character from the associated file.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
Returns the remaining number of characters in this file.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Subclass of PrintWriter that prints to a file. Created by a call to File::create_writer.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
native_close( Int32 handle )Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Internal use.
native_open( String filename ).Int32
Internal use.
native_write( Int32 handle, Int32 datum )
Internal use.
|
| Object Variables |
|---|
|
file_handle : Int32
Internal use.
pos : Int32
Equivalent to the number of characters that have been written.
|
| Object Methods |
|---|
|
capacity().Int32
Returns the minimum number of additional values that can
written with this writer, or (-1) for "unlimited".
clean_up()
Closes the writer. Base aspect Writer does not incorporate
the RequiresCleanup interface, but types for writers that do
this method will be called when there are no more references
to the object.
close()
Closes the file. This should be called after all desired
data has been written to the file.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
flush()The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Orders the writer to write out any buffered data in
preparations for closing the writer.
hash_code().Int32Invariant: close() should always call flush() first.
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
holds_has_another().BooleanHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns "true".
init( String filename )
Initializes this writer to write to the specified file.
The file is opened for writing; close() should be called
when finished.
position().Int32If there's an error opening the file then a FileError() is thrown.
This property-read returns the position of the file,
equivalent to the number of characters that have been written
thus far.
position( Int32 new_pos )
This optional property-write sets the zero-based write
position. It is up to the implementation to define how
repositioning works with gaps and what happens to data at a
later spot after a reposition to an earlier spot.
print( ParsePos p )Not all writers implement this property; those that don't will throw an UnsupportedMethodError when it's accessed.
Prints the given ParsePos in text form.
print( Char ch )
Prints the given Char. The symbol corresponding
to the Unicode value of 'n' will be displayed.
print( Real32 n )
Prints the given Real32 in text form.
print( String st )
Prints the given String.
print( Byte n )
Prints the given Byte in text form.
print( Real64 n )
Prints the given Real64 in text form.
print( Object obj )
Prints the to_String representation of the given object, or
else the world "null" if the 'obj' reference is null.
print( Readable<<Char>> readable )
Prints out every character in the Readable data.
print( Reader<<Char>> reader )
Prints out every character that can be obtained from the
reader.
print( Boolean n )
Prints the given Boolean in text form as "true" or "false".
print( Degrees deg )
Prints out the given degrees value.
print( Radians rad )
Prints out the given radians value.
print( Ternary n )
Prints the given Ternary in text form as "yes", "no", or
"void".
print( Int64 n )
Prints the given Int64 in text form.
println( String st )
Prints the given String value and advances the cursor to the
next line.
println( Boolean n )
Prints the given Boolean value and advances the cursor to the
next line.
println()
Advances the cursor to the next line.
println( Byte n )
Prints the given Byte value and advances the cursor to the
next line.
println( Real64 n )
Prints the given Real64 value and advances the cursor to the
next line.
println( ParsePos p )
Prints the given ParsePos in text form and advances the
cursor to the next line.
println( Reader<<Char>> reader )
Prints out every character that can be obtained from the
reader and advances the cursor to the next line.
println( Char n )
Prints the given Char value and advances the cursor to the
next line.
println( Object obj )
Prints the given object's to_String value and advances
the cursor to the next line.
println( Int64 n )
Prints the given Int64 value and advances the cursor to the
next line.
println( Degrees deg )
Prints out the given degrees value and advances the cursor
to the next line.
println( Readable<<Char>> readable )
Prints out every character in the Readable data and advances
the cursor to the next line.
println( Ternary n )
Prints the given Ternary value and advances the cursor to the
next line.
println( Radians rad )
Prints out the given radians value and advances the cursor
to the next line.
skip( Int32 skip_count )
This optional method repositions the writer to be
'skip_count' values further along.
to_String().StringIf a writer does not implement the 'position' property then an UnsupportedMethodError will be generated when skip() is called.
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
write( DataType value )Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String
Outputs 'value' in an implementation-specific way.
write( Char value )Requires: holds_has_another == true
Writes 'value' in 8 bits.
|
Base type for a Reader that's specialized as a generator. Generators always have another number, can skip() a number of values ahead (through repeated reads), and don't support the to_List operation.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns true - standard generators always have another value.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
is_exhausted().BooleanHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns "true" if this reader does not have another value
or "false" if it does.
peek().DataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
read().DataTypeReaders that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( Int32 skip_count )
Discards 'skip_count' number of values that would otherwise
be returned from this generator.
to_List().DataType[]
Throws an UnsupportedMethodError.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
to_String().StringHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Defines the global methods and variables that form the core of Slag's API.
| Class Variables |
|---|
|
command_line_args : String[]
Java-style command line arguments. If a slag program
"echo.slag" is compiled to an ETC file and run like this:
pi : Radiansslag echo hello worldor compiled to an exe and run like this: echo hello worldThen command_line_args[0] will contain "hello" and command_line_args[1] will contain "world".
Defines the constant "pi". If cos(pi) = -1.0, then
acos(-1.0) = pi.
random_gen : RandomReal64Generator
This random number generator that is seeded with the current
time when the program is run.
stdin : Reader<<Char>>
A Reader<<Char>> that reads characters from the standard
input. This is typically configured to be the keyboard.
stdout : PrintWriter
A Writer<<Char>> that writes characters to the standard
output. This is typically configured to be the console
window.
|
| Class Methods |
|---|
|
abs( Real64 n ).Real64
Returns the absolute value of 'n'.
abs( Int32 n ).Int32
Returns the absolute value of 'n'.
abs( BigInt n ).BigIntabs( Int64 n ).Int64
Returns the absolute value of 'n'.
acos( Real64 xp ).Radians
Returns the arccosine (or "cos^-1") of 'xp'. This is the
angle that a vector would have to be at to have a
proportional length 'xp' along the x axis.
all( Readable<<Boolean>> values ).Boolean
Returns true if all of the given values are "true".
all( Boolean b ).BooleanExample:
local Int32 n = input_Int32
if (all(n % {2, 3..sqrt(n) step 2} != 0))
println( "$ is a prime number!" (n) )
else
println( "$ is not prime." (n) )
endIf
Returns true if 'b' is true. This method is supplied so
that all(a==b) may be called in a template without knowing
whether 'a==b' results in a single boolean or a list of
booleans.
any( Readable<<Boolean>> values ).Boolean
Returns true if any of the given values are "true".
any( Boolean b ).Boolean
Returns true if 'b' is true. This method is supplied so
that any(a==b) may be called in a template without knowing
whether 'a==b' results in a single boolean or a list of
booleans.
as_Int32( Real32 n ).Int32
Reinterprets the 32 bits that compose 'n' as an Int32.
as_Int64( Object obj ).Int64
Returns the memory location that 'obj' is referencing for
debugging purposes.
as_Int64( Real64 n ).Int64
Reinterprets the 64 bits that compose 'n' as an Int64.
as_Real32( Int32 n ).Real32Example: # show the bit pattern corresponding to pi: println( "Pi: $" (pi.as_Int64) )
Reinterprets the 32 bits that compose 'n' as a Real32.
as_Real64( Int64 n ).Real64
Reinterprets the 64 bits that compose 'n' as a Real64.
asin( Real64 yp ).Radians
Returns the arcsine (or "sin^-1") of 'yp'. This is the
angle that a vector would have to be at to have a
proportional length 'yp' along the y axis.
atan( Real64 slope ).Radians
Returns the arctangent (or "tan^-1") of 'slope'. This is
the angle of the vector that has the given y/x 'slope'.
atan2( Real64 y, Real64 x ).RadiansNote: slopes do not have a direction associated with them like vectors do; therefore "atan(1.0/1.0)" is the same as "atan(-1.0/-1.0)". Use atan2(Real64,Real64) to take direction into account.
Returns the arctangent (or "tan^-1") of slope 'y'/'x'. This
is the angle of the vector that has that slope.
ceiling( Real64 n ).Real64Unlike atan(Real64), this method takes the direction into account - atan2(1.0,1.0) will give a different answer than atan2(-1.0,-1.0).
Rounds "n" up to the nearest value.
clamp( Real64 num, Real64 low, Real64 high ).Real64Examples: ceiling( 3.0 ) is 3 ceiling( 3.1 ) is 4
Returns:
clamp( Int32 num, Int32 low, Int32 high ).Int32'low' if num < low 'high' if num > high 'num' otherwise
Returns:
clamp( Int64 num, Int64 low, Int64 high ).Int64'low' if num < low 'high' if num > high 'num' otherwise
Returns:
cos( Radians rad ).Real64'low' if num < low 'high' if num > high 'num' otherwise
Returns the cosine value of angle 'rad'.
cos( Degrees deg ).Real64Given a vector of angle 'rad', the cosine value tells us what proportion of that line lies along the x axis.
Returns the cosine value of angle 'deg'.
create_duplicate( Object existing ).ObjectGiven a vector of angle 'deg', the cosine value tells us what proportion of that line lies along the x axis.
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
floor( Real64 n ).Real64Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Returns the value of 'n' rounded down.
format_string( Radians rad, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).Stringprintln( floor(3.9) ) #prints: 3 println( floor(-3.9) ) #prints: -4
Returns a formatted string representation of 'rad'.
format_string( String st, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( Char num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( Int32 num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( Byte num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( Degrees deg, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'deg'.
format_string( Boolean num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( ParsePos p, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of the given
ParsePos.
format_string( Real64 num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( Int64 num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( Object obj, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'obj'.
format_string( Ternary num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
fractional_part( Real64 n ).Real64
Returns the fractional part of the given value.
hash_code( Real32 n ).Int32Example: println( fractional_part(3.9) ) #prints: 0.9
Returns a hash code for primitive 'n'.
hash_code( Int64 n ).Int32
Returns a hash code for primitive 'n'.
hash_code( Ternary n ).Int32
Returns a hash code for primitive 'n'.
hash_code( Real64 n ).Int32
Returns a hash code for primitive 'n'.
hash_code( Boolean n ).Int32
Returns a hash code for primitive 'n'.
hash_code( Int32 n ).Int32
Returns a hash code for primitive 'n'.
hash_code( Object obj ).Int32
Returns "null" if the object is null or else the result of
obj.hash_code.
init_class()
Internal use.
input_Int32( [String prompt] ).Int32
Displays the given prompt and calls read_Int32 to read
and return a number.
input_Int64( [String prompt] ).Int64
Displays the given prompt and calls read_Int64 to read
and return a number.
input_String( [String prompt] ).String
Displays the given prompt and calls read_line to read
and return a number.
is_NaN( Real32 n ).Boolean
"Not a number" (NaN) values can't be compared normally; for example
(NaN == NaN) is false. The Slag compiler detects comparisons against
literal "NaN" and calls this method. This method can also be called
when comparing against a variable that may or may not be a NaN value.
is_NaN( Real64 n ).Boolean
"Not a number" (NaN) values can't be compared normally; for example
(NaN == NaN) is false. The Slag compiler detects comparisons against
literal "NaN" and calls this method. This method can also be called
when comparing against a variable that may or may not be a NaN value.
is_alphanumeric( Char ch ).Boolean
Returns "true" if 'ch' is an alphanumeric value (0-9, a-z,
A-Z).
is_digit( Char ch, [Int32 base] ).Boolean
Returns true if the given character is a valid digit in the
specified number base (2 to 36 where bases greater than
10 accept characters "a..z" or "A..Z" as digits 10..35).
is_even( Int64 n ).Boolean
Returns "true" if 'n' is an even number.
is_even( Int32 n ).Boolean
Returns "true" if 'n' is an even number.
is_even( BigInt n ).Booleanis_hex_digit( Char ch ).Boolean
Returns "true" if 'ch' is an base-16 digit (0-9, a-f, A-F).
is_letter( Char ch ).Boolean
Returns "true" if 'ch' is a letter of the alphabet (A-Z, a-z).
is_lowercase( Char ch ).Boolean
Returns "true" if 'ch' is an lowercase letter (a-z).
is_odd( Int64 n ).Boolean
Returns "true" if 'n' is an odd number.
is_odd( BigInt n ).Booleanis_odd( Int32 n ).Boolean
Returns "true" if 'n' is an odd number.
is_power_of_two( Int64 n ).Boolean
Returns "true" if 'n' is a power of 2.
is_power_of_two( Int32 n ).Boolean
Returns "true" if 'n' is a power of 2.
is_uppercase( Char ch ).Boolean
Returns "true" if 'ch' is an uppercase letter (A-Z).
left_rotated( Int64 n, Int32 num_bits ).Int64
Returns 'n' with its bits left-rotated by 'num_bits' digits.
left_rotated( Int32 n, Int32 num_bits ).Int32
Returns 'n' with its bits left-rotated by 'num_bits' digits.
left_shifted( Int64 n, Int32 num_bits ).Int64
Returns 'n' with its bits left-shifted by 'num_bits' digits.
Zero bits are shifted in on the right side.
left_shifted( Int32 n, Int32 num_bits ).Int32
Returns 'n' with its bits left-shifted by 'num_bits' digits.
Zero bits are shifted in on the right side.
max( Real64 a, Real64 b ).Real64
Returns the highest of the two values 'a' and 'b'.
max( Int64 a, Int64 b ).Int64
Returns the highest of the two values 'a' and 'b'.
max( Int32 a, Int32 b ).Int32
Returns the highest of the two values 'a' and 'b'.
min( Int64 a, Int64 b ).Int64
Returns the lowest of the two values 'a' and 'b'.
min( Int32 a, Int32 b ).Int32
Returns the lowest of the two values 'a' and 'b'.
min( Real64 a, Real64 b ).Real64
Returns the lowest of the two values 'a' and 'b'.
min_bits( Int32 n ).Int32
Returns the minimum number of bits required to represent the
given value. For example, min_bits(4) would return 3,
since 3 bits can represent the values 0..7.
new_Degrees( Radians rad ).DegreesInvariant: result >= 1 and result <= 32 (2^result-1) >= n if (n < 0) result == 32
Creates a Degrees value of the same angle as 'rad'.
new_Degrees( Real32 n ).Degrees
Creates a Degrees value of 'n' degrees.
new_Degrees( Real64 n ).Degrees
Creates a Degrees value of 'n' degrees.
new_Radians( Degrees deg ).Radians
Creates a Radians value of the same angle as 'deg'.
new_Radians( Real64 n ).Radians
Creates a Radians value of 'n' radians.
new_Radians( Real32 n ).Radians
Creates a Radians value of 'n' radians.
op*( Degrees deg, Real64 factor ).Degrees
Returns "deg" scaled by "factor".
op*( Real64 factor, Degrees deg ).Degrees
Returns "deg" scaled by "factor".
op*( Real64 factor, Radians rad ).Radians
Returns "rad" scaled by "factor".
op*( Radians rad, Real64 factor ).Radians
Returns "rad" scaled by "factor".
op+( Degrees deg1, Degrees deg2 ).Degrees
Returns the sum of two angles. Called automatically
when there's an expression of the form "a1 + a2".
op+( Radians rad1, Radians rad2 ).Radians
Returns the sum of two angles. Called automatically
when there's an expression of the form "a1 + a2".
op+( Degrees deg, Radians rad ).Degrees
Returns the sum of two angles. Called automatically
when there's an expression of the form "a1 + a2".
op+( Radians rad, Degrees deg ).Radians
Returns the sum of two angles. Called automatically
when there's an expression of the form "a1 + a2".
op-( Degrees deg1, Degrees deg2 ).Degrees
Returns the difference of two angles. Called automatically
when there's an expression of the form "a1 - a2".
op-( Radians rad, Degrees deg ).Radians
Returns the difference of two angles. Called automatically
when there's an expression of the form "a1 - a2".
op-( Radians rad1 ).Radians
Returns the negative of the given angle. Called automatically
when there's an expression of the form "-a".
op-( Degrees deg1 ).Degrees
Returns the negative of the given angle. Called automatically
when there's an expression of the form "-a".
op-( Degrees deg, Radians rad ).Degrees
Returns the difference of two angles. Called automatically
when there's an expression of the form "a1 - a2".
op-( Radians rad1, Radians rad2 ).Radians
Returns the difference of two angles. Called
automatically when there's an expression of the form "a1 - a2".
op/( Radians rad, Real64 factor ).Radians
Returns "rad" scaled by "factor".
op/( Real64 factor, Degrees deg ).Degrees
Returns "deg" scaled by "factor".
op/( Real64 factor, Radians rad ).Radians
Returns "rad" scaled by "factor".
op/( Degrees deg, Real64 factor ).Degrees
Returns "deg" scaled by "factor".
print( Byte n )
Prints the given Byte to stdout as a human-readable series of
digits.
print( Char n )
Prints the given Char to stdout. The symbol corresponding
to the Unicode value of 'n' will be displayed.
print( Real64 n )
Prints the given Real64 to stdout as a human-readable series
of digits.
print( Object obj )
Prints the to_String() value of the given Object to stdout.
If the 'obj' reference is null, the word "null" is printed
out instead.
print( ParsePos p )
Prints the given ParsePos to stdout.
print( Int64 n )
Prints the given Int64 to stdout as a human-readable series of
digits.
print( Boolean n )
Prints the given Boolean to stdout as the words "true" or
"false".
print( Degrees deg )
Prints the given degrees value.
print( Ternary n )
Prints the given Ternary to stdout as the words 'yes', 'no',
or 'void'.
print( Radians rad )
Prints the given radians value.
println( Degrees deg )
Prints the given degrees value and advances the cursor to the
next line.
println()
Moves the cursor to the next line.
println( Object obj )
Prints the given object and advances the cursor to the next
line.
println( ParsePos p )
Prints the given ParsePos to stdout and advances the
cursor to the next line.
println( Char n )
Prints the given Char value and advances the cursor to the
next line.
println( Byte n )
Prints the given Byte value and advances the cursor to the
next line.
println( Real64 n )
Prints the given Real64 value and advances the cursor to the
next line.
println( Int64 n )
Prints the given Int64 value and advances the cursor to the
next line.
println( Ternary n )
Prints the given Ternary value and advances the cursor to the
next line.
println( Radians rad )
Prints the given radians value and advances the cursor to the
next line.
println( Boolean n )
Prints the given Boolean value and advances the cursor to the
next line.
random_Boolean().Boolean
Returns either "true" or "false" with equal likelihood.
random_Degrees().Degrees
Returns a random angle in the range (0,360) exclusive.
random_Int32( Int32 limit ).Int32
Returns a normalized, evenly distributed random integer in
the range [0,limit) - includes 0 but does not include limit.
random_Int32( Int32 low, Int32 high ).Int32Example: println( random_Int32(100) ) #prints a number 0..99
Returns a random integer between low and high, inclusive.
random_Int32().Int32
Returns a normalized, evenly distributed random integer in
the range [-2^31,2^31-1] inclusive.
random_Radians().Radians
Returns a random angle in the range (0,2*pi) exclusive.
random_Real64( Real64 low, Real64 high ).Real64
Returns a normalized, evenly distributed random real number in
the range (low,high) exclusive (does not include low or high).
random_Real64().Real64
Returns a normalized, evenly distributed random real number in
the range (0.0,1.0) exclusive (does not include 0.0 or 1.0).
read_Int32().Int32
Reads a line of text in from the user - up to the [ENTER]
key being pressed - and attempts to parse an Int32 value
from the text. If the input is not a well-formed integer
value then an InvalidOperandError is thrown.
read_Int64().Int64
Reads a line of text in from the user - up to the [ENTER]
key being pressed - and attempts to parse an Int64 value
from the text. If the input is not a well-formed integer
value then an InvalidOperandError is thrown.
read_line().String
Reads a line of text in from the user - up to the [ENTER]
key being pressed - and returns the line of text as a
String. The end-of-line characters are not part of the
string and are discarded.
right_rotated( Int32 n, Int32 num_bits ).Int32
Returns 'n' with its bits right-rotated by 'num_bits' digits.
right_rotated( Int64 n, Int32 num_bits ).Int64
Returns 'n' with its bits right-rotated by 'num_bits' digits.
right_shifted( Int64 n, Int32 num_bits ).Int64
Returns 'n' with its bits right-shifted by 'num_bits' digits.
Zero bits are shifted in on the right side.
right_shifted( Int32 n, Int32 num_bits ).Int32
Returns 'n' with its bits right-shifted by 'num_bits' digits.
Zero bits are shifted in on the right side.
right_xshifted( Int64 n, Int32 num_bits ).Int64
Returns 'n' with its bits right-shifted by 'num_bits' digits.
The most significant bit is duplicated with each shift to
preserve the sign of the number.
right_xshifted( Int32 n, Int32 num_bits ).Int32
Returns 'n' with its bits right-shifted by 'num_bits' digits.
The most significant bit is duplicated with each shift to
preserve the sign of the number.
round_off( Real64 n ).Real64
Returns the value of 'n' rounded off.
rounded_up_to_power_of_two( Int32 n ).Int32println( round_off(3.4) ) #prints: 3 println( round_off(3.5) ) #prints: 4 println( round_off(-3.4) ) #prints: -4 println( round_off(-3.5) ) #prints: -3
Returns 'n' rounded up to the next power of 2. If it is
already a power of two it is returned unmodified.
set_up_stdio()Requires: n >= 0Invariant: 2^(result-1) < n and 2^(result) >= n
Sets up stdin and stdout.
sign( Real64 n ).Real64
Returns the sign of 'n' as an Real64 value:
sign( Int32 n ).Int321 when n > 0 -1 when n < 0 0 when n == 0
Returns the sign of 'n' as an Int32 value:
sign( Int64 n ).Int641 when n > 0 -1 when n < 0 0 when n == 0
Returns the sign of 'n' as an Int64 value:
sin( Radians rad ).Real641 when n > 0 -1 when n < 0 0 when n == 0
Returns the sine value of angle 'rad'.
sin( Degrees deg ).Real64Given a vector of angle 'rad', the sine value tells us what proportion of that line lies along the y axis.
Returns the sine value of angle 'deg'.
sleep( Int32 ms )Given a vector of angle 'deg', the sine value tells us what proportion of that line lies along the y axis.
Puts this program to sleep for the given number of milliseconds.
For example, to sleep for 2.5 seconds:
sqrt( Int32 n ).Int32sleep( 2500 )
Returns the square root of 'n'.
sqrt( Real64 n ).Real64
Returns the square root of 'n'.
sqrt( Int64 n ).Int64
Returns the square root of 'n'.
tan( Radians rad ).Real64
Returns the tangent value of angle 'rad'.
tan( Degrees deg ).Real64Given a vector of angle 'rad', the tangent value gies us the slope (y/x) of that vector.
Returns the tangent value of angle 'deg'.
time_ms().Int64Given a vector of angle 'deg', the tangent value gies us the slope (y/x) of that vector.
Returns the current time in milliseconds since January 1,
1970.
to_Degrees( Radians rad ).DegreesExample: local var start_ms = time_ms ...code... local var elapsed_ms = time_ms - start_ms println( "Elapsed time: $ seconds" (elapsed_ms / 1000.0) )
Converts the given value from radians into degrees.
to_Radians( Degrees deg ).Radians
Converts the given value from degrees into radians.
to_String( Object obj ).String
Returns the string representation of the given object.
Returns "null" if the 'obj' reference is null, else returns
the result of obj.to_String().
to_String( Real64 n ).String
Returns a string representation of 'n'.
to_String( Int32 n, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 32 or 8 digits will be
returned, respectively.
to_String( Int64 n, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 64 or 16 digits will be
returned, respectively.
to_String( Byte n ).String
Returns a string representation of 'n'.
to_String( Int16 n, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 16 or 4 digits will be
returned, respectively.
to_String( Char ch ).String
Returns a string representation of 'ch'. This will be a
string containing 'ch' as its single character.
to_String( Int8 n, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 8 or 2 digits will be
returned, respectively.
to_String( Boolean n ).String
Returns a string representation of boolean 'n' as "true"
or "false".
to_String( Int32 n ).String
Returns a string representation of 'n'.
to_String( Int64 n ).String
Returns a string representation of 'n'.
to_String( Radians rad ).String
Returns a string representation of the given radians value.
to_String( Ternary n ).String
Returns a string representation of boolean 'n' as "yes",
"no", or "void".
to_String( Char ch, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 16 or 8 digits will be
returned, respectively. Note that to_String('A') returns
"A" while to_String('A',10) returns "65".
to_String( Degrees deg ).String
Returns a string representation of the given value in degrees.
to_String( Byte n, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 8 or 2 digits will be
returned, respectively.
to_String( ParsePos p ).String
Returns a string representation of the given ParsePos.
to_value( Char ch ).Int32
Converts the character 'ch' into the value it represents
where '0'..'9' represent values 0..9 and 'a'..'z' (or
'A'..'Z' represent values 10..35.
type_name( Int32 n ).StringReturns: 0..35
Returns "Int32".
type_name( Int64 n ).String
Returns "Int64".
type_name( Int8 n ).String
Returns "Int8".
type_name( Int16 n ).String
Returns "Int16".
type_name( Byte n ).String
Returns "Byte".
type_name( Ternary n ).String
Returns "Ternary".
type_name( Boolean n ).String
Returns "Boolean".
type_name( Real32 n ).String
Returns "Real32".
type_name( Real64 n ).String
Returns "Real64".
type_name( Char n ).String
Returns "Char".
wrap( Int64 num, Int64 low, Int64 high ).Int64
Returns 'num' constrained to the number cycle low..high;
similar to modulo.
wrap( Int32 num, Int32 low, Int32 high ).Int32Example: println( wrap(8,1,6) ) #prints: 2 println( wrap(-7,1,6) ) #prints: 5
Returns 'num' constrained to the number cycle low..high;
similar to modulo.
wrap( Real64 num, Real64 low, Real64 high ).Real64Example: println( wrap(8,1,6) ) #prints: 2 println( wrap(-7,1,6) ) #prints: 5
Returns 'num' constrained to the number cycle low..high;
similar to modulo.
Example: println( wrap( 2.2, 0.0, 1.0) ) #prints: 0.2000 println( wrap(-1.4, 0.0, 1.0) ) #prints: 0.6000 |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
to_String().StringHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Defines a lookup table that uses chained hashing (bins of linked lists) to associate key/value pairs. All the keys must be of the same datatype and all the values must be of the same datatype, but the keys can be different datatypes from the values.
The following requirements must be met for the following types to be used as KeyType:
primitive (Int32, Real64, etc)
No restrictions.
compound
You must define the following class method:
Global::hash_code(CompoundType c).Int32
reference
You must override hash_code.Int32 in the class type.
Class String already defines hash_code.
See Object::hash_code() for more information on creating hash
codes.
HashTable defaults to 16 bins with an average bin size of 3 - once the average number of entries per bin exceeds 3 the number of bins is doubled. Alternate values may be specified in the initializer.
Example:
local HashTable<<String,Int32>> numbers() numbers[ "one" ] = 1 numbers[ "two" ] = 2 numbers[ "three" ] = 3 ...local HashTable<<String,Int32>> factors() factors[ "hundred" ] = 10^2 factors[ "thousand" ] = 10^3 factors[ "million" ] = 10^6 ...
local String word_form = "two million" local String[] words = word_form.tidy.split println( numbers[words[0]] * factors[words[1]] ) #prints: 2000000
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
average_bin_size : Real64
Limit of the average bin size. If there are 16 bins and an
average_bin_size of 3, the table will expand once there
are 3 items in each bin (3*16=48 items total, 48/16 bins=3
avg) or when a single bin has 48 items (48 / 16 = 3 avg).
This value is used to calculate the max_entries before the
table expands.
bins : HashTableBin<<KeyType,ValueType>>[]hash_mask : Int32
Internal use. Set to the number of bins-1. E.g. for 16 bins
the mask is 15, since hash_code & 15 -> 0..15
max_bins : Int32
The number of bins (default: 512 ) at which the table will
stop auto-expanding # and instead continue to fill the
existing bins however large they may get.
max_entries : Real64
Recalculated from average_bin_size each time the table
expands.
num_entries : Int32 |
| Object Methods |
|---|
|
clear()
Removes all mappings from this hash table.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
contains( KeyType key ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Returns "true" if 'key' has an associated value in this table
that can be retrieved with get().
count().Int32
Returns the number of mappings in this table.
create_duplicate().Object
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
expand_table()The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Resizes this hash table to have double the number of bins as
before.
find( KeyType key ).Mapping<<KeyType,ValueType>>
Finds the underlying Mapping that defines the mapping
between 'key' and 'value'. Returns a null reference if no
mapping is present. Useful for optimizing conditional table
operations.
get( KeyType key ).ValueTypeExample without find():
if (table.contains(id))
person = table[id]
endIf
Example with find() - a bit faster:
local var mapping = table.find(id)
if (mapping isNot null)
person = mapping.value
endIf
Retrieves the value (previously mapped with set()) associated
with 'key'. Throws a NoSuchElementError if 'key' has not been
defined.
get_bin( KeyType key ).HashTableBin<<KeyType,ValueType>>hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( [Int32 num_bins], [Real64 average_bin_size] )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this hash table with the given number of bins
(default 16) and the given average_bin_size (default 3.0).
keys().HashTableKeyReader<<KeyType,ValueType>>
Returns a reader that iterates through this hash table's keys.
These are not guaranteed to be an any particular order.
remove( KeyType key ).ValueTypeExample:
local HashTable<<String,Int32>> ages()
ages["Abe"] = 34
ages["Murphy"] = 30
ages["Matt"] = 28
forEach (name in ages.keys)
println( "$ is $ years old." (name,ages[name]) )
#prints:
# Abe is 34 years old.
# Matt is 28 years old.
# Murphy is 30 years old.
endForEach
Removes the mapping between 'key' and its value from this table.
Throws a NoSuchElementError if 'key' has not been defined.
set( Mapping<<KeyType,ValueType>> entry )
Associates the given value with the given key. When get() is
called with 'key', 'value' will be returned.
set( KeyType key, ValueType value )
Associates the given value with the given key. When get() is
called with 'key', 'value' will be returned.
to_String().String
Returns a string representation of this hashtable.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
values().HashTableValueReader<<KeyType,ValueType>>Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String
Returns a reader that iterates through this hash table's values.
These are not guaranteed to be an any particular order.
|
Internal use. A linked list of key/value mappings for a given hashcode bin.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
entries : Mapping<<KeyType,ValueType>>[] |
| Object Methods |
|---|
|
add_entry( KeyType key, ValueType value ).Boolean add_entry( Mapping<<KeyType,ValueType>> entry ).Boolean clear() compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
find_entry( KeyType key ).Mapping<<KeyType,ValueType>>The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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'). hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
index_of_entry( KeyType key ).Int32Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init( Int32 initial_capacity ) to_String().String type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Reader that iterates through a HashTable's keys.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
bins : Reader<<HashTableBin<<KeyType,ValueType>>>> entries : Reader<<Mapping<<KeyType,ValueType>>>> |
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Reader<<HashTableBin<<KeyType,ValueType>>>> bins )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().KeyType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
prep_next()Readers that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Prepares the next value that will be used by peek() and
read(). As a composite range reader, this involves advancing
to the next range reader if the current range reader is
empty.
read().KeyType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Reader that iterates through a HashTable's values.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
bins : Reader<<HashTableBin<<KeyType,ValueType>>>> entries : Reader<<Mapping<<KeyType,ValueType>>>> |
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Reader<<HashTableBin<<KeyType,ValueType>>>> bins )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().ValueType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
prep_next()Readers that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Prepares the next value that will be used by peek() and
read(). As a composite range reader, this involves advancing
to the next range reader if the current range reader is
empty.
read().ValueType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Performs an in-place HeapSort on the given list.
Example:
local var nums = {2,3,1,5,4}
HeapSort<<Int32>>.sort( nums, SORT.ascending )
println( nums ) #prints: {1,2,3,4,5}
---- ALGORITHM (ascending order) ---------------------------------
For sorting purposes, a "heap" is a complete binary tree where the only guarantee is that each child node has a value less or equal to than its parent.
HEAP CREATION
The first step in a heap sort is to construct a heap by adding each unsorted number to it. To do this we put the number in the next available position in the heap. We then maintain the heap invariant by switching the node with its parent so long as it's greater than its parent.
Example:
Unsorted numbers:ORDERING{2,3,1,5,4}
Heap after adding three numbers:
3 / \ 2 1
Add the next number, "5":
3 / \ 2 1 / 5
Heapify:
3 3 5 / \ / \ / \ 2 1 -> 5 1 -> 3 1 / / / 5 2 2
Finished heap after all five numbers:
5 / \ 4 1 / \ 2 3
The heap is complete. The root node contains the highest (and consequently last) value in our sorted list. So pluck it off to be the end of our list.
- Ordered list: 5
/ \
4 1
/ \
2 3
Now if we can quickly "fix" the heap, the root node of the
repaired heap will be the next-to-last number in the list.
Instead of trying to decide which child to move up to the root
(etc., etc.), take the LAST leaf of the heap, put it on top,
and poke it back down to an appropriate level by recursively
swapping it with the higher of its two children until it's
greater than both of its children.
3 Ordered list: 5
/ \
4 1 ***Last moves to root position - needs fix
/
2
4 Ordered list: 5
/ \
3 1 ***Push down by recursively swapping with the
/ greater of its two children - fixed.
2
3 Ordered list: 4 5
/ \
2 1 ***Pluck next number, move last leaf to root,
push root down - complete step.
2 Ordered list: 3 4 5
/
1 ***Pluck next number, move last leaf to root,
push root down - complete step.
...
Ordered list: 1 2 3 4 5
PRACTICAL IMPLEMENTATION
Despite how it may seem at first, HeapSort is a very low-cost algorithm.
A binary tree can be represented as a linear array where 'nodes[i]' has children 'nodes[2*i+1]' and 'nodes[2*i+2]' and parent 'nodes[(i-1)/2]'.
At any point in the sorting process the number of elements in the list and the number of element in the heap sums to the same N. This means we can use one end of the original array for the list of numbers and the other end for the heap. If you like, imagine a partition that slides up and back down - the left side is the heap, the right side is the unsorted (and then sorted) numbers.
Here's a side-by-side comparison of adding the 4th number during heap construction in both conceptual and practical formats (the "|" isn't IN the array but shows the division between heap and list):
Heap after adding three numbers:During ordering, pulling the top number off and replacing it with the last leaf of the tree becomes as simple as swapping the numbers at the beginning and end of the heap array before sliding the partition back one.CONCEPTUAL PRACTICAL
3 {3 2 1 | 5 4} / \ 2 1
Remaining: {5 4}
Adding the fourth number:
CONCEPTUAL PRACTICAL
3 {3 2 1 5 | 4} / \ 2 1 / 5
Remaining: {4}
Heapifying:
CONCEPTUAL PRACTICAL
3 {3 5 1 2 | 4} / \ 5 1 / 2
5 {5 3 1 2 | 4} / \ 3 1 / 2
Finished heap: {5 4 1 2 3}
v v
Order next: {5 4 1 2 3 |} - swap first and last
{3 4 1 2 5 |} - swapped
{3 4 1 2 | 5} - scoot partition down
{4 3 1 2 | 5} - repair heap
v v
Order next: {4 3 1 2 | 5}
{2 3 1 4 | 5}
{2 3 1 | 4 5}
{3 2 1 | 4 5}
...
{| 1 2 3 4 5} - Finished!
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
sort( DataType[] list, [SORT order] )Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Sorts 'list' in-place using heapsort.
If 'DataType' is a class it must define DataType::compare_to(DataType).Ternaryand DataType::equals(DataType).BooleanIf 'DataType' is a compound then Global::compare_to(DataType,DataType).Boolean must be defined. |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
to_String().StringHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Defines a suite of read operations on indexed data. Incorporated by both Strings and IndexedData (and consequently Lists).
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
contains( DataType value ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Returns "true" if this data contains the given value.
count().Int32
Returns the number of elements in this set of data.
create_duplicate().Object
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
create_reader().Reader<<DataType>>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.
Returns a reader that can be used to read() this data one
element at a time.
end( Int32 from_end ).DataType
Equivalent to get( (count-1) + from_end ).
equals( Object other ).BooleanFor example, end(0) is equivalent to last() and end(-1) is equivalent to get(count-2).
Returns true if this object is equivalant to another.
first().DataTypeThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the first element of this data. This convenience
method is equivalent to get(0).
format( String str_format, [String repeater_chars] ).String
Easier convenience method to accomplish to_String(prefix,prepeat,suffix).
format( String prefix, String prepeat, String suffix ).StringBreaks down a simple format like this:
{$[ or $]}
Into a prefix="{", prepeat=" or ", suffix="}".
Normally "[]" brackets are used to denote the repeater portion, but this may be specified otherwise. Example: local Int32[] nums = 11..15 println( nums.to_String( "[$:+$:]", ":" ) # prints: [11+12+13+14+15]
Converts this list into a string using the following format:
from( Int32 starting_index ).Reader<<DataType>>prefix + $0 + [prepeat + $N]* + suffixwhere "$0" is the first element and $N is every other element. Example:
local Int32[] nums = 11..15
println( nums.to_String("[", "+", "]") )
# prints: [11+12+13+14+15]
Returns a reader that can be used to read() this data one
element at a time with the given 'starting_index'.
from( Range<<Int32>> range ).Reader<<DataType>>
Returns a reader that can be used to read() this data one
element at a time from the given starting index up to and
including the ending index.
get( Int32 index ).DataType
Returns the element at the zero-based index.
hash_code().Int32Note that the compiler translates all calls of the form: a[i]into: a.get(i)Requires: 0 <= index < count
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
index_of( DataType value, [Int32 starting_index] ).Int32Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns the first index that the given value occurs at
starting at index 0 by default. (-1) is returned if
'value' is not found.
indices().Range<<Int32>>
Returns this data's range of indices (0..count-1).
is_empty().Boolean
Returns true if count == 0.
is_not_empty().Boolean
Returns true if count > 0.
last().DataType
Returns the last element of this data. This convenience
method is equivalent to get(count-1).
last_index_of( DataType value, [Int32 starting_index] ).Int32
Returns the last index that the given value occurs at
starting at index (count-1) by default. (-1) is
returned if 'value' is not found.
modification_count().Int32
Returns a counter representing the number of times items
has been added to or removed. Used by readers to detect
concurrent list modification errors. For example, when an inner
method removes an item from a list the modification counter
is incremented. An outer "forEach" loop will detect that the
count is different from its original value and throw a
ConcurrentListModification error.
random().DataType
Returns an element of this data at random.
reverse_indices().Range<<Int32>>
Returns this data's range of indices reversed (count-1 downTo 0).
reverse_order().Reader<<DataType>>Example:
local Int32[] nums = {5..7}
forEach (i in nums.reverse_indices) println( i )
#prints: 2 | 1 | 0
Returns a reader that can be used to read() this data one
element at a time from the last element (N-1) to the first (0).
to_List().DataType[]
Converts this indexed data into a list.
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Extends IndexReadOperations with a set of index-based write operations.
Note: some operations (like 'get') that would seem better suited for inclusion in 'IndexReadOperations' are put here instead so that String can incorporate IndexReadOperations and have get methods that return strings rather than lists.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
contains( DataType value ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Returns "true" if this data contains the given value.
count().Int32
Returns the number of elements in this set of data.
create_duplicate().Object
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
create_reader().Reader<<DataType>>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.
Returns a reader that can be used to read() this data one
element at a time.
end( Int32 from_end ).DataType
Equivalent to get( (count-1) + from_end ).
equals( DataType value ).Boolean[]For example, end(0) is equivalent to last() and end(-1) is equivalent to get(count-2).
Returns a list of Boolean values where each value true if
the corresponding element of this indexed data equals()
the given value.
equals( Readable<<DataType>> other ).Boolean
Returns true if each element of this data equals() each
corresponding element from in 'other'.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
first().DataTypeThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the first element of this data. This convenience
method is equivalent to get(0).
format( String str_format, [String repeater_chars] ).String
Easier convenience method to accomplish to_String(prefix,prepeat,suffix).
format( String prefix, String prepeat, String suffix ).StringBreaks down a simple format like this:
{$[ or $]}
Into a prefix="{", prepeat=" or ", suffix="}".
Normally "[]" brackets are used to denote the repeater portion, but this may be specified otherwise. Example: local Int32[] nums = 11..15 println( nums.to_String( "[$:+$:]", ":" ) # prints: [11+12+13+14+15]
Converts this list into a string using the following format:
from( Int32 starting_index ).Reader<<DataType>>prefix + $0 + [prepeat + $N]* + suffixwhere "$0" is the first element and $N is every other element. Example:
local Int32[] nums = 11..15
println( nums.to_String("[", "+", "]") )
# prints: [11+12+13+14+15]
Returns a reader that can be used to read() this data one
element at a time with the given 'starting_index'.
from( Range<<Int32>> range ).Reader<<DataType>>
Returns a reader that can be used to read() this data one
element at a time from the given starting index up to and
including the ending index.
get( Int32 index ).DataType
Returns the element at the zero-based index.
get( Readable<<Int32>> indices ).DataType[]Note that the compiler translates all calls of the form: a[i]into: a.get(i)Requires: 0 <= index < count
Gets the element at each of the given zero-based 'indices'.
get( Readable<<Boolean>> flags ).DataType[]Example:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Returns a new list containing the subset of elements
of which each of the corresponding 'flags' is true.
hash_code().Int32Example:
local Int32[] nums = {1..10}
println( nums[nums % 2 == 0] )
#prints: {2,4,6,8,10}
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
index_of( DataType value, [Int32 starting_index] ).Int32Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns the first index that the given value occurs at
starting at index 0 by default. (-1) is returned if
'value' is not found.
indices().Range<<Int32>>
Returns this data's range of indices (0..count-1).
is_empty().Boolean
Returns true if count == 0.
is_not_empty().Boolean
Returns true if count > 0.
last().DataType
Returns the last element of this data. This convenience
method is equivalent to get(count-1).
last_index_of( DataType value, [Int32 starting_index] ).Int32
Returns the last index that the given value occurs at
starting at index (count-1) by default. (-1) is
returned if 'value' is not found.
modification_count().Int32
Returns a counter representing the number of times items
has been added to or removed. Used by readers to detect
concurrent list modification errors. For example, when an inner
method removes an item from a list the modification counter
is incremented. An outer "forEach" loop will detect that the
count is different from its original value and throw a
ConcurrentListModification error.
random().DataType
Returns an element of this data at random.
reverse()
Reverses the order of the elements in this data.
reverse_indices().Range<<Int32>>
Returns this data's range of indices reversed (count-1 downTo 0).
reverse_order().Reader<<DataType>>Example:
local Int32[] nums = {5..7}
forEach (i in nums.reverse_indices) println( i )
#prints: 2 | 1 | 0
Returns a reader that can be used to read() this data one
element at a time from the last element (N-1) to the first (0).
reversed().IndexedData<<DataType>>
Returns an list containing the elements of this data
in reverse order.
set( Int32 index, DataType value )
Sets the element at the zero-based 'index' to be 'value'.
set( Readable<<Int32>> indices, DataType value )Note that the compiler translates all calls of the form: a[i] = vinto: a.set(i,v)Requires: 0 <= index < count
Sets the element at each of the given 'indices' to the given
'value'.
set( Readable<<Boolean>> flags, DataType value )Example:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Starting at index 0, sets each element to the given 'value'
if the corresponding 'element_flags' are true.
set( Readable<<Int32>> indices, Readable<<DataType>> values )Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = 0
println( nums ) #prints: {0,2,0,4,0}
Sets the element at each of the given 'indices' to each of
the corresponding 'values'.
set( Readable<<Boolean>> element_flags, Readable<<DataType>> values )Requires: The number of indices == the number of values.Example:
local Int32[] nums = {1..5}
nums[0..4 step 2] = {7,8,9}
println( nums )
#prints: {7,2,8,4,9}
Starting at index 0, sets each element to the next of the
given 'values' if the corresponding 'element_flags' are true.
shuffle()Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = -nums
println( nums ) #prints: {-1,2,-3,4,-5}
Swaps every element of this data with another element at a
randomly-chosen position.
shuffled().IndexedData<<DataType>>
Returns a shuffled copy of this data.
subset( Int32 first_index, Int32 last_index ).ArrayList<<DataType>>
Returns the subset of this data between indices
[first_index,last_index] inclusive.
swap( Int32 index_a, Int32 index_b )
Swaps the value at 'index_a' with the one at 'index_b'.
to_List().DataType[]Requires: 0 <= index_a < count 0 <= index_b < countInvariant: this[index_a] = old[index_b] this[index_b] = old[index_a]
Converts this data into a list.
to_String().String
Returns a string representation of this data.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A reader that steps through the values in a set of indexed data.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
counter : Int32 data : IndexReadOperations<<DataType>> last_exclusive : Int32 original_modification_count : Int32 |
| Object Methods |
|---|
|
available().Int32
Returns the number of values that can be read without
blocking - equivalent to 'remaining' in most cases.
close()
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().IndexedDataReader<<DataType>>Returns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Handles duplicating this iterator when "duplicate(iterator_obj)" is called.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( IndexReadOperations<<DataType>> data )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init( IndexReadOperations<<DataType>> data, Int32 first_index, [Int32 count] ) is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().DataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
Sets the zero-based position property of this reader.
position().Int32Requires: new_position >= 0 and new_position < count
Returns the zero-based position property of this reader. The
position is equivalent to the number of values read in so far.
read().DataType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
Returns the number of values remaining to be read.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A reader that steps through the values in a set of indexed data from last to first.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
counter : Int32 data : IndexReadOperations<<DataType>> last_exclusive : Int32 original_modification_count : Int32 |
| Object Methods |
|---|
|
available().Int32
Returns the number of values that can be read without
blocking - equivalent to 'remaining' in most cases.
close()
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().IndexedDataReader<<DataType>>Returns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Handles duplicating this iterator when "duplicate(iterator_obj)" is called.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( IndexReadOperations<<DataType>> data )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init( IndexReadOperations<<DataType>> data, Int32 first_index, [Int32 count] ) is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().DataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
Sets the zero-based position property of this reader.
position().Int32Requires: new_position >= 0 and new_position < count
Returns the zero-based position property of this reader. The
position is equivalent to the number of values read in so far.
read().DataType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
Returns the number of values remaining to be read.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
This base class is designed to quickly allow the creation of input-coverting wrapper classes that read in one type of value and output a different type.
To use, extend a class and define prep_next() to read from 'src', place the prepared output in 'next', and return true on success or false if there's no more data.
For example, here's an input converter that converts a series of integer ordinals into a series of enumeration categories.
enum SUIT
CATEGORIES
spades, hearts, clubs, diamonds
endEnum
class Int32ToSuit : InputConverter<<Int32,SUIT>>
METHODS
method prep_next.Boolean:
if (not src.has_another) return false
next = SUIT.by_ordinal( src.read )
return true
endClass
...
println( Int32ToSuit({1,1,0,3}).to_List )
#prints: {hearts,hearts,spades,diamonds}
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
has_next : Boolean
If "true" then 'next' is a valid value.
next : OutputDataType
The next data that will be returned by peek() or read().
src : Reader<<InputDataType>>
The backing source of values for this reader.
|
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Readable<<InputDataType>> readable )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this BitReader to read from the given reader.
init( Reader<<InputDataType>> src )
Initializes this BitReader to read from the given readable
data.
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().OutputDataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
prep_next().BooleanReaders that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Prepares the next value that will be used by peek() and
read(). Returns "true" if there is another value, "false"
if not.
read().OutputDataType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
This base class is designed to quickly allow a variety of filtering input wrappers to be created. To use, extend a class and override prep_next().
For example, here's a CR filter that strips all Unicode 13 values from a character reader.
class CRFilter : InputFilter<<Char>>
METHODS
method prep_next.Boolean:
repeat
if (not prior.prep_next) return false
until (next != 13)
return true
endClass
...
local String st = "A\r\nB\r\n"
println( st.count ) #prints: 6
st = String( CRFilter(st) )
println( st.count ) #prints: 4
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
has_next : Boolean
If "true" then 'next' is a valid value.
next : DataType
The next data that will be returned by peek() or read().
src : Reader<<DataType>>
The backing source of values for this reader.
|
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Reader<<DataType>> src )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this BitReader to read from the given reader.
init( Readable<<DataType>> readable )
Initializes this BitReader to read from the given readable
data.
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().DataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
prep_next().BooleanReaders that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Prepares the next value that will be used by peek() and
read(). Returns "true" if there is another value, "false"
if not.
read().DataTypeThe default behavior for an InputFilter is as follows: if (not src.has_another) return false next = src.read return trueClasses extending InputFilter will want to override this method.
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Provides a simple way to time an interval. As soon as an IntervalObject is created it starts timing. It may be restarted with start() and stopped with stop(). When to_String(), elapsed_seconds(), or elapsed_ms() is called it returns the time from start to stop or from start to present time if it hasn't been stopped yet.
Example:
local IntervalTimer timer()
sleep(1500)
println( timer )
# prints: 1.50 seconds
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
start_ms : Int64 stop_ms : Int64 |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
elapsed_ms().Int64The 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.
Returns the elapsed number of milliseconds since the
timer was created or since the most recent call to start().
elapsed_seconds().Real64
Returns the elapsed number of seconds since the
timer was created or since the most recent call to start().
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init()Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
This initializer starts the timer.
start()
Restarts the timer.
stop()
Stops the timer; the elapsed time since the timer was
created or since the last call to start() can be
obtained by to_String(), 'elapsed_ms', or 'elapsed_seconds'.
to_String().String
Returns the string "n.dd seconds" where "n.dd" is the
value 'elapsed_seconds'.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Thrown by a method when it identifies one of its parameters as having an invalid value.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init()Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Default initializer.
init( String var_name )
This initializer incorporates the given var_name into the
error message.
init( String var_name, String var_value )
This initializer incorporates the given var_name and the
given illegal value into the error message.
to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String message )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this Error with the given message.
init()to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Wraps an existing character reader and reads lines at a time, discarding CRLF characters.
For example, to print every line of a file with a line number:
local Int32 number = 1
forEach (line in LineReader(File("test.slag")))
println( "$(6) $" (number,line) )
number++
endForEach
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
has_next : Boolean
If "true" then 'next' is a valid value.
next : OutputDataType
The next data that will be returned by peek() or read().
src : Reader<<InputDataType>>
The backing source of values for this reader.
|
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Readable<<InputDataType>> readable )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this BitReader to read from the given reader.
init( Reader<<InputDataType>> src )
Initializes this BitReader to read from the given readable
data.
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().OutputDataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
prep_next().BooleanReaders that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Prepares the next value that will be used by peek() and
read(). Returns "true" if there is another value, "false"
if not.
read().OutputDataType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A LinkedList uses a singly-linked node structure to maintain its list. On the one hand it uses more memory per item and retrievals take O(n) time, but on the other hand there is no "wasted" (unused) memory like there is with ArrayLists and insertions and removals are O(1) once the proper position is found.
Array lists are recommended over linked lists except in situations where there are many different lists.
Slag list syntax defaults to ArrayList usage:
Int32[] array_list()Linked lists must be explicitly created:
Int32[] linked_list = LinkedList<<Int32>>()or
LinkedList<<Int32>> linked_list()Invariant:
count >= 0 capacity >= count data.count == capacity
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
promote( DataType value ).DataType[]Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise
When there is an operation of the form
"DataType + List<<DataType>>" (where DataType is a
primitive or compound), the compiler calls this method to
promote the left-hand side operand to an object.
|
| Object Variables |
|---|
|
counter : Int32
Counts how many items are stored in this list.
first_node : LinkedListNode<<DataType>>
Links to the head and tail of this list.
last_node : LinkedListNode<<DataType>>
Links to the head and tail of this list.
modification_count : Int32 |
| Object Methods |
|---|
|
add( DataType value, Int32 after_index ).List<<DataType>>
Inserts 'value' after the given index.
add( DataType value ).DataType[]Returns: A reference to this list for call-chaining.Requires: after_index >= -1 and after_index < countInvariant: new.count == old.count + 1 new[after_index+1] == value
Adds the given 'value' to the end of this list.
add( Readable<<DataType>> source ).List<<DataType>>Returns a reference to this list for call chaining. Invariant: count = old.count + 1 get[count-1] == value
Adds each item from the Readable source to this list.
capacity().Int32Returns a reference to this list for call-chaining.
This list can store *at least* 'capacity' elements before it
automatically reorganizes its underlying data structures.
ArrayList implementations return the number of unused array
slots; LinkedList implementations return "count + 1" because
their data structure always supports another element.
clear()A lists's capacity should not be used as the condition for a loop since the capacity of some lists (e.g. LinkedLists) never actually changes.
Removes all elements from this list. The capacity
is unchanged.
compare_to( Object other ).TernaryInvariant: new.count == 0 new.capacity == old.capacity
This method is used for ordering (quantitative) comparisons
between this object and another.
compare_to( DataType value ).Ternary[]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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Compares each of this list's values to the given value and
returns a list of Ternary 'gt', 'lt', and 'eq' values.
compare_to( Readable<<DataType>> values ).Ternary[]Only implemented for numerical List types.
Compares each of this list's values to each corresponding
given value and returns a list of Ternary 'gt', 'lt', and
'eq' values.
contains( DataType value ).BooleanOnly implemented for numerical List types.
Returns "true" if this data contains the given value.
count().Int32
Returns how many values there are in this list.
create_duplicate().DataType[]
Creates a duplicate of this list when the "duplicate(list)"
command is given. If the list element type is a reference
type, the new list contains a copy of the same references
to the same objects - the objects themeselves are not
duplicated.
create_reader().Reader<<DataType>>Results: A duplicate list such that "all(this is result)" equals true.
Returns a reader that can be used to read() this data one
element at a time.
discard( Int32 first_index, [Int32 last_index] )
Removes the elements in the specified range. Does not return
the list of removed elements like remove() does. If only
the 'first' parameter is given, elements from 'first' to the
end of the list are discarded.
discard( Range<<Int32>> range )'first' and 'last_node' are clipped to be a valid range.
Removes elements in the specified range.
end( Int32 from_end ).DataTypeRequires: range.is_contiguous_ascending
Equivalent to get( (count-1) + from_end ).
ensure_capacity( Int32 desired_capacity )For example, end(0) is equivalent to last() and end(-1) is equivalent to get(count-2).
Directs a list to prepare itself to hold a total of
'desired_capacity' elements. Proper use prevents ArrayLists
from having to resize their data structures multiple times
over the course of an operation.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
equals( DataType value ).Boolean[]The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns a list of Boolean values where each value true if
the corresponding element of this indexed data equals()
the given value.
equals( Readable<<DataType>> other ).Boolean
Returns true if each element of this data equals() each
corresponding element from in 'other'.
first().DataType
Returns the first element of this data. This convenience
method is equivalent to get(0).
format( String prefix, String prepeat, String suffix ).String
Converts this list into a string using the following format:
format( String str_format, [String repeater_chars] ).Stringprefix + $0 + [prepeat + $N]* + suffixwhere "$0" is the first element and $N is every other element. Example:
local Int32[] nums = 11..15
println( nums.to_String("[", "+", "]") )
# prints: [11+12+13+14+15]
Easier convenience method to accomplish to_String(prefix,prepeat,suffix).
from( Range<<Int32>> range ).Reader<<DataType>>Breaks down a simple format like this:
{$[ or $]}
Into a prefix="{", prepeat=" or ", suffix="}".
Normally "[]" brackets are used to denote the repeater portion, but this may be specified otherwise. Example: local Int32[] nums = 11..15 println( nums.to_String( "[$:+$:]", ":" ) # prints: [11+12+13+14+15]
Returns a reader that can be used to read() this data one
element at a time from the given starting index up to and
including the ending index.
from( Int32 starting_index ).Reader<<DataType>>
Returns a reader that can be used to read() this data one
element at a time with the given 'starting_index'.
get( Int32 index ).DataType
Returns the element at the given zero-based index.
get( Readable<<Boolean>> flags ).DataType[]Requires: 0 <= index and index < count
Returns a new list containing the subset of elements
of which each of the corresponding 'flags' is true.
get( Readable<<Int32>> indices ).DataType[]Example:
local Int32[] nums = {1..10}
println( nums[nums % 2 == 0] )
#prints: {2,4,6,8,10}
Gets the element at each of the given zero-based 'indices'.
hash_code().Int32Example:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
index_of( DataType value, [Int32 starting_index] ).Int32Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns the first index that the given value occurs at
starting at index 0 by default. (-1) is returned if
'value' is not found.
indices().Range<<Int32>>
Returns this data's range of indices (0..count-1).
init( Readable<<DataType>> readable )
Initializes this list to contain all the items from the
'readable' data source.
init()
Creates an empty linked list
insert( DataType value, [Int32 before_index] ).DataType[]
Inserts the 'value' in front of 'before_index'. Elements
at 'begin_index' and higher are logically shifted up by one.
insert( IndexedData<<DataType>> seq, [Int32 before_index] ).DataType[]Returns: A reference to this list for call chaining.Requires: 0 <= before_index and before_index <= countInvariant: this[before_index] = value this[before_index+1] = old[before_index] count = old.count + 1
Inserts all the given values in front of 'before_index'. Elements
at 'begin_index' and higher are logically shifted up by one.
is_empty().BooleanReturns: A reference to this list for call chaining.Requires: 0 <= before_index and before_index <= countInvariant: this[before_index] = value this[before_index+seq.count] = old[before_index] count = old.count + seq.count
Returns true if count == 0.
is_not_empty().Boolean
Returns true if count > 0.
last().DataType
Returns the last element of this data. This convenience
method is equivalent to get(count-1).
last_index_of( DataType value, [Int32 starting_index] ).Int32
Returns the last index that the given value occurs at
starting at index (count-1) by default. (-1) is
returned if 'value' is not found.
modification_count().Int32
Returns a counter representing the number of times items
has been added to or removed. Used by readers to detect
concurrent list modification errors. For example, when an inner
method removes an item from a list the modification counter
is incremented. An outer "forEach" loop will detect that the
count is different from its original value and throw a
ConcurrentListModification error.
op!().DataType[]
Returns a list containing the logical complement of each
value in this list.
op%( DataType value ).DataType[]Only implemented for integer and Boolean List types.
Returns a list of the remainders of each of this list's
values divided by the given value.
op%( Readable<<DataType>> values ).DataType[]Only implemented for numerical List types.
Returns a list of the remainders of each of this list's
values divided by each of the corresponding given values.
op&( DataType value ).DataType[]Only implemented for numerical List types.
Performs a bitwise 'and' operation between each
of this list's values and the given value and returns
a list of results.
op&( Readable<<DataType>> values ).DataType[]Only implemented for integer and Boolean List types.
Performs a bitwise 'and' operation between each
of this list's values and each corresponding given value
and returns a list of results.
op*( Readable<<DataType>> values ).DataType[]Only implemented for integer and Boolean List types.
Multiplies each given value by each of this list's
corresponding values and returns a list of the results.
op*( DataType value ).DataType[]Only implemented for numerical List types.
Multiplies the given value by each of this list's values and
returns a list of the results.
op+( Readable<<DataType>> values ).DataType[]Only implemented for numerical List types.
Adds each given value to each of this list's corresponding
values and returns a list of the results.
op+( DataType value ).DataType[]Only implemented for numerical List types.
Adds the given value to each of this list's values and
returns a list of the results.
op-().DataType[]Only implemented for numerical List types.
Returns a list containing the negative of each value in this
list.
op-( DataType value ).DataType[]Only implemented for numerical List types.
Subtracts the given value from each of this list's values and
returns a list of the results.
op-( Readable<<DataType>> values ).DataType[]Only implemented for numerical List types.
Subtracts each given value from each of this list's
corresponding values and returns a list of the results.
op/( Readable<<DataType>> values ).DataType[]Only implemented for numerical List types.
Divides each of this list's values by each corresponding
given value and returns a list of the results.
op/( DataType value ).DataType[]Only implemented for numerical List types.
Divides each of this list's values by the given value and
returns a list of the results.
op^( DataType value ).DataType[]Only implemented for numerical List types.
Raises each of this list's values to the power of the given
value and returns a list of the results.
op^( Readable<<DataType>> values ).DataType[]Only implemented for numerical List types.
Raises each of this list's values to the power of each
corresponding given value and returns a list of the results.
op|( DataType value ).DataType[]Only implemented for numerical List types.
Performs a bitwise 'or' operation between each
of this list's values and the given value and returns
a list of results.
op|( Readable<<DataType>> values ).DataType[]Only implemented for integer and Boolean List types.
Performs a bitwise 'or' operation between each
of this list's values and each corresponding given value
and returns a list of results.
op~( DataType value ).DataType[]Only implemented for integer and Boolean List types.
Performs a bitwise 'xor' operation between each
of this list's values and the given value and returns
a list of results.
op~( Readable<<DataType>> values ).DataType[]Only implemented for integer and Boolean List types.
Performs a bitwise 'xor' operation between each
of this list's values and each corresponding given value
and returns a list of results.
product().DataTypeOnly implemented for integer and Boolean List types.
Returns the product of all the values contained in this
list-adaptable object.
random().DataTypeOnly implemented for numerical list types.
Returns an element of this data at random.
remove( Range<<Int32>> range ).DataType[]
Removes and returns the elements in the specified range.
See discard() for a variant that's optimal when you don't
need the return value.
remove( Int32 index ).DataTypeRequires: range.is_contiguous_ascending
Removes and returns the element at position 'index'. All
elements higher than 'index' are logically shifted down by one spot
and the list count is decremented.
remove( DataType value ).BooleanReturns: old[index]Requires: 0 <= index and index < countInvariant: new[index] = old[index+1]
Calls remove_value(value). Only available for non-numerical
lists - see note in remove_value().
remove( Int32 first_index, Int32 last_index ).DataType[]
Removes and returns the elements in the specified range.
remove_first().DataType'first' and 'last_node' are clipped to be a valid range. Returns: The list of elements from old[first] through old[last_node].
Equivalent to:
remove_last().DataTypelist.remove(0)
Equivalent to:
remove_value( DataType value ).Booleanlist.remove(list.count-1)
Removes the first occurrence of 'value' from the list.
reverse()Returns: "true" if an occurrence of 'value' was found and removed, or "false" if it was not found.Technical note: this method can't be named remove() because in an Int32[] list, remove(index) and remove(value) would have the same signature.
Reverses the order of the elements in this data.
reverse_indices().Range<<Int32>>
Returns this data's range of indices reversed (count-1 downTo 0).
reverse_order().Reader<<DataType>>Example:
local Int32[] nums = {5..7}
forEach (i in nums.reverse_indices) println( i )
#prints: 2 | 1 | 0
Returns a reader that can be used to read() this data one
element at a time from the last element (N-1) to the first (0).
reversed().IndexedData<<DataType>>
Returns an list containing the elements of this data
in reverse order.
set( Readable<<Int32>> indices, Readable<<DataType>> values )
Sets the element at each of the given 'indices' to each of
the corresponding 'values'.
set( Readable<<Boolean>> element_flags, Readable<<DataType>> values )Requires: The number of indices == the number of values.Example:
local Int32[] nums = {1..5}
nums[0..4 step 2] = {7,8,9}
println( nums )
#prints: {7,2,8,4,9}
Starting at index 0, sets each element to the next of the
given 'values' if the corresponding 'element_flags' are true.
set( Readable<<Boolean>> flags, DataType value )Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = -nums
println( nums ) #prints: {-1,2,-3,4,-5}
Starting at index 0, sets each element to the given 'value'
if the corresponding 'element_flags' are true.
set( Int32 index, DataType value )Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = 0
println( nums ) #prints: {0,2,0,4,0}
Sets the element at the given zero-based index.
set( Readable<<Int32>> indices, DataType value )Requires: 0 <= index and index < count
Sets the element at each of the given 'indices' to the given
'value'.
shuffle()Example:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Swaps every element of this data with another element at a
randomly-chosen position.
shuffled().IndexedData<<DataType>>
Returns a shuffled copy of this data.
sort( [SORT order] )
Sorts this list in place using a HeapSort.
'order' is SORT.ascending by default.
sorted( [SORT order] ).List<<String>>Only implemented for numerical and String lists. To enable it for lists of other types (say, Event), add this augment:
augment List<<Event>>
METHODS
method sort( SORT order=SORT.ascending ):
HeapSort<<DataType>>.sort( this, order )
endAugment
Returns an list containing the elements of this data
sorted into order. Only implemented for numerical and
String lists.
subset( Int32 first_index, Int32 last_index ).ArrayList<<DataType>>
Returns the subset of this data between indices
[first_index,last_index] inclusive.
sum().DataType
Returns the sum of all the values contained in this
list-adaptable object.
swap( Int32 index_a, Int32 index_b )Only implemented for numerical list types.
Swaps the value at 'index_a' with the one at 'index_b'.
to_List().DataType[]Requires: 0 <= index_a < count 0 <= index_b < countInvariant: this[index_a] = old[index_b] this[index_b] = old[index_a]
Satisifies the ListAdaptable aspect of the IndexedData aspect
by returning this list with no modifications.
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Internal use - used by LinkedList.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
next : LinkedListNode<<DataType>> value : DataType |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe 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.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote 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').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( DataType value )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Value initializer.
init( DataType value, LinkedListNode<<DataType>> next )
Value/link initializer
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A List aspect is an ordered collection that is Readable and addressable by index.
Numerical lists incorporate the ListArithmetic<<DataType>> aspect. Integer and Boolean lists incorporate the ListBitwise<<DataType>> aspect.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
promote( DataType value ).DataType[]Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise
When there is an operation of the form
"DataType + List<<DataType>>" (where DataType is a
primitive or compound), the compiler calls this method to
promote the left-hand side operand to an object.
|
| Object Variables |
|---|
|
modification_count : Int32 |
| Object Methods |
|---|
|
add( DataType value ).List<<DataType>>
Appends 'value' to the end of this list.
add( DataType value, Int32 after_index ).List<<DataType>>Returns a reference to this list for call-chaining, e.g.: list.add(3).add(4).add(5)Invariant: new.count == old.count + 1 new.last is value
Inserts 'value' after the given index.
add( Readable<<DataType>> source ).List<<DataType>>Returns: A reference to this list for call-chaining.Requires: after_index >= -1 and after_index < countInvariant: new.count == old.count + 1 new[after_index+1] == value
Adds each item from the Readable source to this list.
capacity().Int32Returns a reference to this list for call-chaining.
This list can store *at least* 'capacity' elements before it
automatically reorganizes its underlying data structures.
ArrayList implementations return the number of unused array
slots; LinkedList implementations return "count + 1" because
their data structure always supports another element.
clear()A lists's capacity should not be used as the condition for a loop since the capacity of some lists (e.g. LinkedLists) never actually changes.
Removes all the items in this list.
compare_to( Readable<<DataType>> values ).Ternary[]Invariant: new.count = 0 new.capacity == old.capacityThis default implementation is non-optimal
Compares each of this list's values to each corresponding
given value and returns a list of Ternary 'gt', 'lt', and
'eq' values.
compare_to( DataType value ).Ternary[]Only implemented for numerical List types.
Compares each of this list's values to the given value and
returns a list of Ternary 'gt', 'lt', and 'eq' values.
compare_to( Object other ).TernaryOnly implemented for numerical List types.
This method is used for ordering (quantitative) comparisons
between this object and another.
contains( DataType value ).BooleanReturns '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.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(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.
This default implementation throws an UnsupportedMethodError.
Returns "true" if this data contains the given value.
count().Int32
Returns the number of elements in this list.
This will be zero or higher.
create_duplicate().DataType[]
Creates and returns a new list containing all the items
in this list.
create_reader().Reader<<DataType>>Called indirectly in response to: duplicate(list) When used with references, note that this method does not duplicate the objects in the list but just the list data structure itself (a shallow copy).
Returns a reader that can be used to read() this data one
element at a time.
discard( Range<<Int32>> range )
Removes elements in the specified range.
discard( Int32 first, [Int32 last] )Requires: range.is_contiguous_ascending
Removes the elements in the specified range. Does not return
the list of removed elements like remove() does. If only
the 'first' parameter is given, elements from 'first' to the
end of the list are discarded.
'first' and 'last' are clipped to be a valid range. This default implementation i |