LST. - List Arrays

<< Click to Display Table of Contents >>

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

LST. - List Arrays

 

📘 SPR List Commands Manual

Welcome to the SPR List Commands Manual! 🌟

This guide provides a comprehensive overview of Lists in SPR, explaining what they are, how to use them, and why they are a powerful tool for scripting. Whether you're a beginner or an experienced user, this manual will help you master Lists with clear explanations and practical examples. Let’s dive in! 🚀

 

📄 Table of Contents

What is a List?

What is a Handle?

What is a List Good For?

List Commands Overview

Code Examples

 

What is a List? 📜

A **List** in SPR is a dynamic, ordered container that can store multiple pieces of data, such as numbers, text, or more complex objects. Think of it as a flexible array or a sequence of elements that you can manipulate in various ways.

Lists are **dynamic**, meaning they can grow or shrink as you add or remove items. They can hold different types of data, including:

1.Strings (e.g., "Hello")

2.Integers (e.g., 123) - 64-bit numbers with a range of -9.22x10^18 to 9.22x10^18

3.Floats (e.g., 3.14) - Floating-point numbers with 18 digits of precision

 

What is a Handle? 🎯

A **Handle** is a unique identifier that allows you to access and manipulate a specific List. When you create a List using LST.New, SPR generates a Handle for it. This Handle is used in all subsequent operations on the List.

 

Example:

 

LST.New|$$LST

Here, $$LST is the Handle for the newly created List. You use this Handle to add, remove, or access items in the List.

 

What is a List Good For? 💡

Lists are incredibly versatile and can be used for a wide range of tasks, including:

Storing Data: Keep track of multiple values, such as names, numbers, or file paths.

Organizing Information: Sort, filter, or group data for easier processing.

Building Strings: Combine multiple text segments into a single string.

Managing Files: Store file paths or contents for batch processing.

Simulating Stacks or Queues: Use Lists to implement advanced data structures like FIFO (First-In-First-Out) or LIFO (Last-In-First-Out).

 

More on the SPR-List Data Structure

A List in SPR is a flexible data structure with the following characteristics:

Ordered: Items are stored in the order they are added.

Dynamic: Lists can grow or shrink as items are added or removed.

Versatile: Lists can hold different types of data, such as strings, integers, or floats.

 

Is a List FIFO, LIFO, or Something Else? 🔄

A List in SPR is neither strictly FIFO nor LIFO. Instead, it’s a general-purpose container that can behave like both depending on how you use it:

 

FIFO (First-In-First-Out) Behavior

You can use a List as a Queue (FIFO structure) by:

Adding items to the end of the List using LST.Add.

Removing items from the beginning of the List using LST.PopFirst.

 

Example:

 

' Create a List

LST.New|$$LST

 

' Add items to the end (FIFO behavior)

LST.Add|$$LST|Apple

LST.Add|$$LST|Banana

LST.Add|$$LST|Cherry

 

' Remove items from the beginning

LST.PopFirst|$$LST|$$RES

MBX. Popped: $$RES ' Output: Apple

LST.PopFirst|$$LST|$$RES

MBX. Popped: $$RES ' Output: Banana

 

' Free the List

LST.End|$$LST

 

LIFO (Last-In-First-Out) Behavior

You can use a List as a Stack (LIFO structure) by:

Adding items to the end of the List using LST.StkPush.

Removing items from the end of the List using LST.StkPop.

 

Example:

 

' Create a List

LST.New|$$LST

 

' Push items onto the stack (LIFO behavior)

LST.StkPush|$$LST|Apple

LST.StkPush|$$LST|Banana

LST.StkPush|$$LST|Cherry

 

' Pop items from the end

LST.StkPop|$$LST|$$RES

MBX. Popped: $$RES ' Output: Cherry

LST.StkPop|$$LST|$$RES

MBX. Popped: $$RES ' Output: Banana

 

' Free the List

LST.End|$$LST

 

General-Purpose Behavior

A List can also be used as a general-purpose container where you can:

Insert items at any position using LST.InsPrev or LST.InsNext.

Remove items from any position using LST.DelPrev or LST.DelNext.

Access items by their position using LST.First, LST.Last, LST.Next, or LST.Prev.

 

List Commands Overview 🛠️

Here’s a quick overview of the most common LST commands:

 

Container Management

LST.New|$$LST[|Type]: Creates a new List.

LST.End|$$LST: Frees the List from memory.

LST.Clear|$$LST: Removes all items from the List.

LST.Count|$$LST|$$RES: Returns the number of items in the List.

 

Adding and Removing Items

LST.Add|$$LST|Value: Adds an item to the end of the List.

LST.Ins|$$LST|Value: Inserts an item at the beginning of the List.

LST.DelPrev|$$LST|$$NOD: Removes the item before the specified node.

LST.DelNext|$$LST|$$NOD: Removes the item after the specified node.

 

Accessing Items

LST.First|$$LST|$$RES: Gets the first item in the List.

LST.Last|$$LST|$$RES: Gets the last item in the List.

LST.Get|$$LST|$$NOD|$$RES: Retrieves the value of a specific node.

LST.Set|$$LST|$$NOD|Value: Updates the value of a specific node.

 

Stack and Queue Operations

LST.StkPush|$$LST|Value: Pushes a value onto the stack (end of the List).

LST.StkPop|$$LST|$$RES: Pops the top value from the stack.

LST.QuePush|$$LST|Value: Adds a value to the queue (end of the List).

LST.QuePop|$$LST|$$RES: Removes the first value from the queue.

 

Advanced Operations

LST.Clone|$$LST|$$RES: Creates a copy of the List.

LST.Store|$$LST|$$RES: Saves the List as a string.

LST.Restore|$$LST|$$STR: Restores a List from a string.

LST.BuildStr|$$LST|$$RES: Combines all items into a single string.

 

🎉 Congratulations!

You now understand the basics of Lists in SPR and how to use them effectively. With this knowledge, you can start building more advanced scripts and automate complex tasks. Happy scripting! 🚀

 

Next Steps:

1.Experiment with the examples above.

2.Explore more advanced List commands like LST.Clone and LST.Store.

3.Combine Lists with other SPR features for even more powerful scripts!

 

Happy Listing!