|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > ARS. - Array's > !ARS. - Container Cloning > ARS. - Container Cloning |
MiniRobotLanguage (MRL)
ARS.Clone
Clones the specified array and optionally stores the handle of the new array in a variable.
Intention
The ARS.Clone command creates an exact copy of the specified array, including its data type and content. The cloned array is independent of the original array, meaning modifications to one array will not affect the other. This is useful when you need to preserve the state of an array for later use or comparison.
Illustration:
📦 Original Array: [1, 2, 3, 4, 5]
📦 Cloned Array: [1, 2, 3, 4, 5]
🔄 Independent copies
🔑 Handle of cloned array stored in $$NEW
Syntax
ARS.Clone|$$ARS[|$$NEW]
Parameter Explanation
P1 - $$ARS - (Variable)
The handle of the original array to be cloned.
P2 - $$NEW (optional) - (Variable)
The variable to store the handle of the cloned array. If omitted, the handle is placed on the Top of Stack (TOS).
Example
'***********************************
' ARS.Clone - Sample 1
'***********************************
ARS.New|$$ARS|s
ARS.Add|$$ARS|1
ARS.Add|$$ARS|2
ARS.Add|$$ARS|3
ARS.Clone|$$ARS|$$NEW
DBP.New Cloned array handle: $$NEW
ARR.End|$$ARS
ARR.End|$$NEW
'
'***********************************
' ARS.Clone - Sample 2
'***********************************
ARS.New|$$ARS|i
ARS.Add|$$ARS|100
ARS.Add|$$ARS|200
ARS.Add|$$ARS|300
ARS.Clone|$$ARS
DBP.New Cloned array handle on TOS
ARS.New|$$ARS2|f
ARS.Add|$$ARS2|1.1
ARS.Add|$$ARS2|2.2
ARS.Add|$$ARS2|3.3
ARS.Clone|$$ARS2|$$NEW2
DBP.New Cloned array handle: $$NEW2
ARR.End|$$ARS
ARR.End|$$ARS2
ARR.End|$$NEW2
'
Remarks
-
Limitations:
-
See also:
•