Data Structures in the DAL Standard Library
The Dist Agent Language (DAL) standard library includes a small set of core data structures that cover most everyday programming tasks: lists, dictionaries, sets, and tuples. These structures shape how you store, organize, and move data through a program, and each one has a different tradeoff between flexibility, lookup speed, and immutability.
Lists
Lists are ordered collections of items. They are the default choice when sequence matters or when you need to add, remove, or update elements over time.
Use a list when you want to:
- preserve the order of items
- store repeated values
- append new values as a program runs
- access items by position
Because lists are mutable, they are useful for working data that changes during execution. That flexibility makes them common in loops, pipelines, and intermediate results.
Dictionaries
Dictionaries store data as key-value pairs. They are the right choice when you want to associate one piece of information with another, such as a name with a score, a setting with a value, or an identifier with a record.
Use a dictionary when you want to:
- look up values by key
- model structured records
- group related fields together
- update values without rebuilding the whole collection
Dictionaries are especially useful when the key is more important than the position of an item. In practice, they are one of the most common ways to represent configuration, metadata, and object-like data.
Sets
Sets are collections of unique items. They are useful when membership matters more than order and when duplicates should be removed automatically.
Use a set when you want to:
- test whether an item exists in a collection
- avoid duplicate entries
- compare groups of values
- perform operations like union or intersection
Sets are a strong fit for tags, permissions, deduplication, and any workflow where uniqueness is important.
Tuples
Tuples are ordered collections that cannot be changed after creation. They are useful for fixed groupings of related values, especially when the data should stay stable.
Use a tuple when you want to:
- group values that belong together
- protect data from accidental modification
- return multiple values from a function
- represent a fixed-size record
Because tuples are immutable, they communicate intent clearly: the value is meant to be read, not edited.
Choosing the right structure
A simple rule of thumb helps:
- List: ordered, changeable sequence
- Dictionary: keyed lookup and structured records
- Set: unique membership and fast deduplication
- Tuple: fixed grouping of values
Choosing the right data structure early makes DAL code easier to read, faster to reason about, and less error-prone.
Conclusion
DAL’s standard data structures are small in number but broad in use. Lists, dictionaries, sets, and tuples each solve a different class of problem, and most programs rely on all four. Learning when to use each one is a practical step toward writing clearer and more efficient DAL code.