|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > !ARM. - Multidimensional Dynamic Arrays > Array Management > ARM. - Array Operations |
MiniRobotLanguage (MRL)
ARM.GetType
Retrieves the data type of a two-dimensional array, storing it in a variable.
Intention
The ARM.GetType command determines the data type of a two-dimensional (2D) array and stores it in a specified variable, allowing developers to identify whether the array holds strings, integers, or floating-point numbers. This is a crucial command for type checking in MiniRobotLanguage, enabling safe data manipulation and validation for tasks like ensuring compatibility before operations (e.g., verifying a game board’s data type before setting values), confirming image pixel data types, or checking matrix types 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.GetType provides essential metadata for managing this grid, returning “s” for strings, “i” for integers, or “f” for floating-point numbers. It’s particularly useful in applications requiring dynamic type handling, such as games, image processing, or scientific computing, where ensuring correct data types prevents errors during operations like ARM.Set, ARM.Get, or ARM.Fill.
Illustration:
🔍 2D Array Type Check: A chessboard-like grid with handle $$ARR, created as a string array, has its type retrieved, storing “s” in $$TYP to confirm its data type.
🔑 Handle: $$ARR remains valid, with the type (“s”, “i”, or “f”) available for verification.
Syntax
ARM.GetType|$$ARR|$$TYP
Parameter Explanation
P1 - $$ARR - (Variable, 5 characters max)
The handle of the 2D array whose data type is to be retrieved. This variable, limited to 5 characters, must contain a valid handle created by ARM.New, and it remains valid after the operation.
P2 - $$TYP - (Variable, 5 characters max)
The variable where the array’s data type will be stored. This must be a valid variable name, limited to 5 characters, and will contain a single character: “s” for strings, “i” for integers, or “f” for floating-point numbers, as specified during ARM.New.
Examples
'--------------------------------------------------------
' ARM.GetType - Sample 1: Checking Data Types of Different Arrays
'--------------------------------------------------------
ARM.New|$$ARR|s
ARM.GetType|$$ARR|$$TYP
JIV.$$TYP!s|Lab_failed
DBP.Array $$ARR is a string array (type “s”)
ARM.End|$$ARR
ARM.New|$$ARI|i
ARM.GetType|$$ARI|$$TYP
JIV.$$TYP!i|Lab_failed
DBP.Array $$ARI is an integer array (type “i”)
ARM.End|$$ARI
ARM.New|$$ARF|f
ARM.GetType|$$ARF|$$TYP
JIV.$$TYP!f|Lab_failed
DBP.Array $$ARF is a floating-point array (type “f”)
ARM.End|$$ARF
'
'--------------------------------------------------------
' ARM.GetType - Sample 2: Verifying Type Before Setting Values in a Game Board
'--------------------------------------------------------
ARM.New|$$ARR|s
ARM.Redim|$$ARR|2|2
ARM.GetType|$$ARR|$$TYP
IF|$$TYP|==|s
DBP.Array $$ARR is a string array, safe to set string values
ARM.Set|$$ARR|1|1|King
ARM.Set|$$ARR|1|2|Queen
ELSE
DBP.Error: Array type mismatch, expected strings
END
ARM.End|$$ARR
'
'--------------------------------------------------------
' ARM.GetType - Sample 3: Verifying Type Before Numeric Operations in a Matrix
'--------------------------------------------------------
ARM.New|$$ARR|i
ARM.Redim|$$ARR|2|2
ARM.GetType|$$ARR|$$TYP
IF|$$TYP|==|i
DBP.Array $$ARR is an integer array, safe to set numeric values
ARM.Set|$$ARR|1|1|100
ARM.Set|$$ARR|1|2|200
ELSE
DBP.Error: Array type mismatch, expected integers
END
ARM.End|$$ARR
'
Remarks
- The array handle must be stored in a variable with a maximum length of 5 characters (e.g., $$ARR, $$ARI) and must be valid (created by ARM.New) before using ARM.GetType. Use ARM.Validate to ensure the handle is valid if there’s any doubt.
- The data type returned in $$TYP is a single character: “s” for strings, “i” for integers, or “f” for floating-point, as specified when the array was created with ARM.New. This information is critical for ensuring type compatibility before operations like ARM.Set, ARM.Get, or ARM.Fill, as shown in the examples with conditional logic.
- The performance of retrieving the array type in MRL is extremely fast, with negligible overhead, as it simply accesses metadata stored with the array handle. This command is ideal for type verification in real-time applications like games, image processing, or scientific computing, where ensuring data type consistency prevents runtime errors.
- This command is foundational for type-safe programming, enabling developers to adaptively handle 2D arrays based on their data type, such as verifying a game board’s string values, confirming numeric pixel intensities, or ensuring matrix operations use the correct numeric type.
Limitations
- The array handle variable must not exceed 5 characters and must be valid; attempting to get the type of an invalid handle may cause runtime errors.
- The variable for the type ($$TYP) must be a valid variable name, limited to 5 characters; invalid variable names may result in errors or undefined behavior.
- The command only returns the original data type set during ARM.New and does not account for runtime changes or mixed data (which isn’t supported in MRL’s 2D arrays). Use ARM.SetType cautiously, as it can alter the array’s type, requiring revalidation with ARM.GetType.
- 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
• ARM.Set
• ARM.Get