Parameterized class for one-dimensional arrays.
Description
Notes
Notes
Notes
| Initialize a one-dimensional array of elements. |
| Initialize a one-dimensional array of elements. |
| Initialize a one-dimensional array of elements. |
| Initialize a one-dimensional array of elements. |
| Gets or sets the efficient-size of self |
| Supports iteration using |
| Gets the size of (i.e. number of elements in) self. |
| The underlying |
| Appends e to the end of self. |
| Deletes all elements from self. |
| Returns a clone of self. |
| Constructs a new Sequence from self, using the length elements starting at start. |
| Concatenates s1 to the end of self. |
| Compares its argument with self for structural equality. |
| Returns a clone of self, with elements filtered out. |
| Returns a clone of self, with elements filtered out, based on their keys (indices). |
| Returns a specific element. |
| Returns a specific element, along with a bool that signifies whether the indicated element was found. |
| Indicates whether its argument is a valid index in self. |
| Inserts e into self immediately before the position designated by index. |
| Called by the serialization code when a class instance is to be written. |
| Removes and returns an element from the end of self. |
| Pushes e onto the end of self. |
| Removes one or more successive elements from self. |
| Reverses the order of the elements in self. |
| Sets the element for a given index. |
| Sets the size of self. |
| Sorts the elements of self. The sorting algorithm employed is stable; i.e., it does not change the relative order of equal elements. |
| Splices s1 into self immediately before the position designated by index. |
| Returns the element at the top of self, viewed as a stack, without modifying self. This is the last element of the sequence. |
Initialize a one-dimensional array of elements.
Initialize a one-dimensional array of elements.
Example
{let my-array:{Array-of String} = {new {Array-of String}}}
{let my-array:{Array-of String} =
{new {Array-of String}, "apple", "banana", "cherry"}}
Initialize a one-dimensional array of elements.
Initialize a one-dimensional array of elements.
Gets or sets the efficient-size of self
Description
Supports iteration using
Description
Gets the size of (i.e. number of elements in) self.
The underlying
Appends e to the end of self.
Example
| Example | |
{value
|| Declare and initialize an array with String
|| elements.
let my-array:{Array-of String} =
{new {Array-of String}, "Tom", "Dick", "Harry"}
|| Append an element to the end of the array.
{my-array.append "Sally"}
|| Use a VBox to display the contents of price.
|| Add each element to the VBox, then display
|| the VBox.
let message:VBox = {VBox}
{for each-element:String in my-array do
{message.add each-element}
}
message
}
|
Notes
Deletes all elements from self.
Example
| Example | |
{value
|| Declare and initialize my-array (an array
|| of String).
let my-array:{Array-of String} =
{new {Array-of String}, "apple", "banana", "cherry"}
|| Clear the array.
{my-array.clear}
|| Check if the array is empty.
{text The array is empty is...
{value my-array.empty?}}
}
|
Returns a clone of self.
Returns
Description
Example
| Example | |
{value
|| Declare and initialize array-1 (the
|| original array).
let array-1:{Array-of String} =
{new {Array-of String}, "apple", "banana", "cherry"}
|| Initialize array-2 with a clone of the
|| contents of array-1.
let array-2:{Array-of String} = {array-1.clone}
|| Use a VBox to display the contents of array-2.
|| Iterate over the contents of array-2, adding
|| them to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in array-2 do
{message.add each-element}
}
message
}
|
Notes
Constructs a new Sequence from self, using the length elements starting at start.
Example
| Example | |
{value
|| Declare and initialize array-1 (the
|| original array).
let array-1:{Array-of String} =
{new {Array-of String}, "apple", "banana", "cherry", "plum"}
|| Declare and initialize array-2 with a clone of the
|| two elements starting at index 1 of array-1.
let array-2:{Array-of String} = {array-1.clone-range 1, 2}
|| Use a VBox to display the contents of array-2.
|| Iterate over the contents of array-2, adding
|| them to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in array-2 do
{message.add each-element}
}
message
}
|
Notes
Concatenates s1 to the end of self.
Example
| Example | |
{value
|| Declare and initialize an array with String
|| elements.
let my-array:{Array-of String} =
{new {Array-of String}, "Tom", "Dick", "Harry"}
|| Declare and initialize another array with
|| String elements.
let your-array:{Array-of String} =
{new {Array-of String}, "Mary", "Sally"}
|| Concatenate the elements of your-array onto
|| the end of my-array.
{my-array.concat your-array}
|| Use a VBox to display the contents of my-array.
|| For each key in my-array, add an HBox to the VBox.
|| The HBox contains the relevant key and element.
|| Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in my-array do
{message.add each-element}
}
message
}
|
Notes
Compares its argument with self for structural equality.
Returns
Description
Example
| Example | |
|| Declare and initialize array-1 (an array
|| of String) with three elements.
{let array-1:{Array-of String} =
{new {Array-of String}, "apple", "banana", "cherry"}
}
|| Declare and initialize array-2 (an array
|| of String) with two elements.
{let array-2:{Array-of String} =
{new {Array-of String}, "apple", "banana"}
}
|| Determine if the arrays are equal.
The arrays are equal is... {array-1.equal? array-2}
|| Add an element to array-2.
{array-2.append "cherry"}
|| And test the arrays for equality again.
After the append operation, the arrays are equal is...
{array-1.equal? array-2}
|
Returns a clone of self, with elements filtered out.
Returns
Example
| Example | |
{value
|| Declare and initialize array-1 (an array
|| of String).
let array-1:{Array-of String} =
{new {Array-of String}, "apple", "banana", "cherry"}
|| Create a clone array-2 that contains the elements
|| of array-1 with strings that begin with the letter
|| 'a' filtered out.
let array-2:{Array-of String} =
{array-1.filter-clone
{proc {str:String}:bool
{return str[0] != 'a'}
}
}
|| Use a VBox to display the contents of array-2.
|| Iterate over the contents of array-2, adding them
|| to the VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in array-2 do
{message.add each-element}
}
message
}
|
Notes
Returns a clone of self, with elements filtered out, based on their keys (indices).
Returns
Example
| Example | |
{value
|| Declare and initialize an array with String
|| elements.
let my-array:{Array-of String} =
{new {Array-of String}, "Tom", "Dick", "Harry"}
|| Create a clone that contains the elements of the
|| original, except that elements with even keys are
|| filtered out.
let new-array:{Array-of String} =
{my-array.filter-keys-clone
{proc {index:int}:bool
{return (index mod 2) == 0}
}
}
|| Use a VBox to display the contents of new-array.
|| Add each element to the VBox, then display
|| the VBox.
let message:VBox = {VBox}
{for each-element:String in new-array do
{message.add each-element}
}
message
}
|
Notes
Returns a specific element.
Returns
Example
| Example | |
|| Declare and initialize an array with String
|| elements.
{let my-array:{Array-of String} =
{new {Array-of String},
"apple",
"banana",
"cherry"
}
}
|| Display the element at index 2.
{my-array.get 2}
|
Notes
| Example | |
{value
|| Declare and initialize an array with String
|| elements.
let my-array:{Array-of String} =
{new {Array-of String},
"apple",
"banana",
"cherry"
}
|| Display the element at index 2.
my-array[2]
}
|
Returns a specific element, along with a bool that signifies whether the indicated element was found.
Returns
Notes
Indicates whether its argument is a valid index in self.
Returns
Description
Example
| Example | |
{value
|| Declare and initialize an array with String
|| elements.
let my-array:{Array-of String} =
{new {Array-of String}, "Tom", "Dick", "Harry"}
|| Check if there is an element at index 3.
|| Remember that the first element in an array
|| is at index 0.
{if {my-array.in-bounds? 3} then
{text It is there!}
else
{text It is not there.}
}
}
|
Notes
Inserts e into self immediately before the position designated by index.
Example
| Example | |
{value
|| Declare and initialize an array with String
|| elements.
let my-array:{Array-of String} =
{new {Array-of String}, "Tom", "Dick", "Harry"}
|| Insert an element at position 1. Subsequent
|| elements are shifted one position to the right.
{my-array.insert "Mary", 1}
|| Insert an element at position 4.
{my-array.insert "Sally", 4}
|| Use a VBox to display the contents of price.
|| Add each element to the VBox, then display
|| the VBox.
let message:VBox = {VBox}
{for each-element:String in my-array do
{message.add each-element}
}
message
}
|
Notes
Called by the serialization code when a class instance is to be written.
Description
Notes
Removes and returns an element from the end of self.
Description
Example
| Example: Pop an Element from a Stack | |
![]() | |
|| Declare and initialize an array with String
|| elements.
{let my-array:{Array-of String} =
{new {Array-of String}, "Tom", "Dick", "Harry"}}
|| Pop an element from the array.
{text The return value of a pop operation is...}
{my-array.pop}
|| Use a VBox to display the contents of my-array.
|| Add each element to the VBox, then embed the
|| VBox within another for display.
{let message:VBox = {VBox}}
{for each-element:String in my-array do
{message.add each-element}
}
{VBox
{text After the pop operation, the array has the
following elements...},
{value message}
}
|
Notes
Pushes e onto the end of self.
Description
Example
| Example: Push an Element onto a Stack | |
{value
|| Declare and initialize an array with String
|| elements.
let my-array:{Array-of String} =
{new {Array-of String}, "Tom", "Dick", "Harry"}
|| Append an element to the end of the array.
{my-array.push "Sally"}
|| Use a VBox to display the contents of my-array.
|| Add each element to the VBox, then display
|| the VBox.
let message:VBox = {VBox}
{for each-element:String in my-array do
{message.add each-element}
}
message
}
|
Notes
Removes one or more successive elements from self.
Description
Example
| Example | |
{value
|| Declare and initialize an array with String
|| elements.
let my-array:{Array-of String} =
{new {Array-of String},
"apple",
"banana",
"cherry"
}
|| Remove the element at index 1.
{my-array.remove 1}
|| Use a VBox to display the contents of my-array.
|| For each element in my-array, add a string to the
|| VBox. Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in my-array do
{message.add each-element}
}
message
}
|
Reverses the order of the elements in self.
Example
| Example | |
{value
|| Declare and initialize an array with String
|| elements.
let my-array:{Array-of String} =
{new {Array-of String}, "Tom", "Dick", "Harry"}
|| Reverse the order of the elements.
{my-array.reverse}
|| Use a VBox to display the contents of price.
|| Add each element to the VBox, then display
|| the VBox.
let message:VBox = {VBox}
{for each-element:String in my-array do
{message.add each-element}
}
message
}
|
Notes
Sets the element for a given index.
Description
Example
| Example | |
|| Declare and initialize a hash table with
|| String keys and int elements.
|| Declare and initialize an array with String
|| elements.
{let my-array:{Array-of String} =
{new {Array-of String},
"apple",
"banana",
"cherry"
}
}
|| Set the element at index 1 to "plum".
{my-array.set 1, "plum"}
|| Use a VBox to display the contents of my-array.
|| For each element in my-array, add an HBox to the
|| VBox. The HBox contains the relevant index and
|| element. Then display the VBox.
{let message:VBox = {VBox}}
{for key each-element:int in my-array do
{message.add {HBox each-element, " ", {my-array.get each-element}}}
}
{value message}
|
Notes
| Example | |
|| Declare and initialize an array with String
|| elements.
{let my-array:{Array-of String} =
{new {Array-of String},
"apple",
"banana",
"cherry"
}
}
|| Set the element at index 1 to "plum".
{set my-array[1] = "plum"}
|| Use a VBox to display the contents of my-array.
|| For each element in my-array, add an HBox to the
|| VBox. The HBox contains the relevant index and
|| element. Then display the VBox.
{let message:VBox = {VBox}}
{for key each-element:int in my-array do
{message.add {HBox each-element, " ", {my-array.get each-element}}}
}
{value message}
|
Sets the size of self.
Notes
Sorts the elements of self. The sorting algorithm employed is stable; i.e., it does not change the relative order of equal elements.
Example
| Example | |
{value
|| Declare and initialize an array with String
|| elements.
let my-array:{Array-of String} =
{new {Array-of String}, "Tom", "Dick", "Harry"}
|| Sort the elements.
{my-array.sort}
|| Use a VBox to display the contents of price.
|| Add each element to the VBox, then display
|| the VBox.
let message:VBox = {VBox}
{for each-element:String in my-array do
{message.add each-element}
}
message
}
|
| Example | |
{value
|| Declare and initialize an array with int
|| elements.
let my-array:{Array-of int} =
{new {Array-of int}, 7, 69, 13, 33, 22}
|| Sort the elements into descending order.
{my-array.sort comparison-proc =
{proc {x:int, y:int}:bool
{return x > y}
}
}
|| Use a VBox to display the contents of my-array.
|| Then display the VBox.
let message:VBox = {VBox}
{for each-element:int in my-array do
{message.add each-element}
}
message
}
|
Notes
Splices s1 into self immediately before the position designated by index.
Example
| Example | |
{value
|| Declare and initialize an array with String
|| elements.
let my-array:{Array-of String} =
{new {Array-of String}, "Tom", "Dick", "Harry"}
|| Declare and initialize another array with
|| String elements.
let your-array:{Array-of String} =
{new {Array-of String}, "Mary", "Sally"}
|| Insert the elements of your-array into my-array
|| at index 1. Subsequent elements of my-array
|| are shifted to the right.
{my-array.splice your-array, 1}
|| Use a VBox to display the contents of my-array.
|| For each key in my-array, add an HBox to the VBox.
|| The HBox contains the relevant key and element.
|| Then display the VBox.
let message:VBox = {VBox}
{for each-element:String in my-array do
{message.add each-element}
}
message
}
|
Notes
Returns the element at the top of self, viewed as a stack, without modifying self. This is the last element of the sequence.
Returns
Description
Example
| Example: Get the Top Element on a Stack | |
![]() | |
|| Declare and initialize an array with String
|| elements.
{let my-array:{Array-of String} =
{new {Array-of String}, "Tom", "Dick", "Harry"}
}
|| View the top of the stack.
{text The return value of a top-of-stack operation is...}
{my-array.top-of-stack}
|| Use a VBox to display the contents of my-array.
|| Add each element to the VBox, then embed the
|| VBox within another for display.
{let message:VBox = {VBox}}
{for each-element:String in my-array do
{message.add each-element}
}
{VBox
{text After the top-of-stack operation, the array has
the following elements...},
{value message}
}
|
Notes