Skip to content

Support sparse array literals in Podlang - #541

Open
robknight wants to merge 1 commit into
mainfrom
podlang_sparse_array_literals
Open

Support sparse array literals in Podlang#541
robknight wants to merge 1 commit into
mainfrom
podlang_sparse_array_literals

Conversation

@robknight

Copy link
Copy Markdown
Collaborator

POD2 arrays can be sparse, with arbitrary indices. Podlang literal array syntax only supports zero-indexed arrays, with no missing indices between elements.

This PR adds syntax for sparse arrays:

[10: 20, 5: 41, 11, 85]

Where an index is given, that index must be used. Where an index is not given, the index is that of the immediately preceding entry plus one. If no indices are given, the first entry has the index 0 and each counts up from there, which is the same behaviour as the existing array literal.

Allow array elements to specify indices while preserving dense literal syntax and implicit increments. Reject duplicate or unrepresentable indices, lower literals to sparse containers, and print indexed arrays without traversing the entire container.
@robknight
robknight requested a review from ed255 August 27, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant