Stack Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Arrays and Data-Structures > STK. - Stack > STK.Operations >

Stack Operations

STK.Clear

Previous Next

 


MiniRobotLanguage (MRL)

 

STK.Clear|$$LST

Delete all data in the container while keeping the handle valid.

 

Intention

The STK.Clear command is used to clear all elements from a stack. This operation resets the stack but does not invalidate the stack handle, allowing for subsequent operations without the need to create a new stack.

This command is useful when the stack needs to be reused in different parts of a script without the overhead of recreating it.

 

 

Syntax

 

STK.Clear|$$LST

 

Parameter Explanation

 

P1 - $$LST: The stack handle that references the stack to be cleared. This handle remains valid after the operation.

 

 

Example

 

'***********************************

' Example 1: Clear a Stack and Validate

'***********************************

STK.New|$$LST

STK.Push|$$LST|Hello

STK.Clear|$$LST

STK.Count|$$LST|$$RES

JIV.$$RES!0|Lab_Failed

STK.End|$$LST

ENR.

 

'***********************************

' Example 2: Clear and Reuse a Stack

'***********************************

STK.New|$$LST

STK.Push|$$LST|Data1

STK.Clear|$$LST

STK.Push|$$LST|Data2

STK.Peek|$$LST|$$RES

JIS.$$RES!Data2|Lab_Failed

STK.End|$$LST

ENR.

 

 

 

 

Remarks

- After clearing a stack, the handle remains valid, so you can reuse it without creating a new stack.

- Clearing a stack does not release its memory until STK.End is called.

 

Limitations:

- The stack handle must be valid before calling STK.Clear. Invalid handles will result in an error.

 

See also:

STK.New

STK.End