|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > !ARM. - Multidimensional Dynamic Arrays > Array Operations > ARM. - Array Operations |
MiniRobotLanguage (MRL)
ARM.DeleteRow
Deletes a row at a specified position in a two-dimensional array, shifting remaining rows upward.
Intention
The ARM.DeleteRow command removes a row at a specified position within a two-dimensional (2D) array, shifting all rows below that position upward to fill the gap. This is a key command for dynamically reducing data structures in MiniRobotLanguage, enabling developers to shrink a 2D array during runtime, such as removing a row from a game board (e.g., trimming a chessboard-like grid), contracting a pixel grid for image processing, or reducing a matrix for mathematical computations. 2D arrays, visualized as a grid like a chessboard with rows and columns (e.g., [1,1] to [8,8]), are emulated within a one-dimensional structure in MRL, and ARM.DeleteRow provides flexibility for applications requiring adaptive data removal, such as real-time simulations, games, or data management tasks. The deleted row’s data is lost, and the array’s handle and column structure remain intact, making it ideal for dynamic resizing without recreation.
Illustration:
➖ 2D Array Row Deletion: A chessboard-like grid with handle $$ARR, originally 4x3, has row 2 deleted, shifting rows upward (e.g., [King, Queen, Bishop; Pawn, Knight, Rook; ...] becomes [King, Queen, Bishop; Pawn, Knight, Rook] in a 3x3 structure).
🔑 Handle: $$ARR remains valid, with the row removed and remaining data shifted.
Syntax
ARM.DeleteRow|$$ARR|$$POS
Parameter Explanation
P1 - $$ARR - (Variable, 5 characters max)
The handle of the 2D array from which the row will be deleted. This variable, limited to 5 characters, must contain a valid handle created by ARM.New, and it remains valid after the operation.
P2 - $$POS - (Variable, 5 characters max)
The position (row index) of the row to delete. This must be a positive integer within the range 1 to the current number of rows (as retrieved by ARM.GetDims), representing the deletion point in the grid (e.g., 2 to delete row 2 from a chessboard).
Examples
'***********************************
' ARM.DeleteRow - Sample 1: Removing a Row from a Game Board
'***********************************
ARM.New|$$ARR
ARM.Set|$$ARR|1|1|King
ARM.Set|$$ARR|2|1|Queen
ARM.Set|$$ARR|3|1|Pawn
DBP.2D Array (chessboard-like) before deletion: [King, ...; Queen, ...; Pawn, ...] (3x2)
SET|$$POS|2
ARM.DeleteRow|$$ARR|$$POS
DBP.2D Array after deletion: [King, ...; Pawn, ...] (2x2, Queen row removed)
ARM.End|$$ARR
'
'***********************************
' ARM.DeleteRow - Sample 2: Removing a Row from an Image Pixel Grid
'***********************************
ARM.New|$$ARR|f
ARM.Set|$$ARR|1|1|1.5
ARM.Set|$$ARR|2|1|-2.7
ARM.Set|$$ARR|3|1|3.14
DBP.2D Array (pixel grid) before deletion: [1.5, ...; -2.7, ...; 3.14, ...] (3x2)
SET|$$POS|2
ARM.DeleteRow|$$ARR|$$POS
DBP.2D Array after deletion: [1.5, ...; 3.14, ...] (2x2, -2.7 row removed)
ARM.End|$$ARR
'
'***********************************
' ARM.DeleteRow - Sample 3: Removing a Row from a Matrix
'***********************************
ARM.New|$$ARR|i
ARM.Set|$$ARR|1|1|100
ARM.Set|$$ARR|2|1|200
ARM.Set|$$ARR|3|1|300
DBP.2D Array (matrix) before deletion: [100, ...; 200, ...; 300, ...] (3x2)
SET|$$POS|2
ARM.DeleteRow|$$ARR|$$POS
DBP.2D Array after deletion: [100, ...; 300, ...] (2x2, 200 row removed)
ARM.End|$$ARR
'
Remarks
- The array handle must be stored in a variable with a maximum length of 5 characters (e.g., $$ARR, $$TMP) and must be valid (created by ARM.New) before using ARM.DeleteRow. Use ARM.Validate to ensure the handle is valid if there’s any doubt, and ARM.GetDims to check current dimensions for proper positioning.
- The position ($$POS) must be within the range 1 to the current number of rows; out-of-bounds positions will result in errors. Ensure $$POS is a positive integer, matching the grid structure (e.g., 2 to delete the second row of a chessboard).
- The deleted row’s data is permanently lost, so ensure this action is intentional, especially in applications like games (removing level rows), image processing (shrinking pixel grids), or scientific computing (reducing matrices). Use ARM.Get to back up data if needed before deletion.
- The performance of deleting a row in a 2D array in MRL, due to its emulation within a one-dimensional structure, may introduce moderate overhead, especially for large arrays, as existing data must be shifted upward. However, this is typically acceptable for most practical use cases, such as small game boards or pixel grids, though frequent deletions in very large arrays should be minimized for performance optimization.
Limitations
- The array handle variable must not exceed 5 characters and must be valid; attempting to delete a row from an invalid handle may cause runtime errors.
- The position ($$POS) must be within bounds (1 to current rows); out-of-bounds positions will result in errors or undefined behavior.
- Deleting rows from very large 2D arrays frequently may impact performance due to data shifting in the emulation, though this is typically manageable for most applications like game boards or small matrices. For large arrays, consider batching deletions or using alternative data structures if performance is critical.
- The command assumes the handle refers to a 2D array; using it on other data types or structures may lead to undefined behavior or errors.
See also:
• ARM.New