Add a new stack data type for storing ordered data#969
Draft
mavnn wants to merge 9 commits intoinkle:masterfrom
Draft
Add a new stack data type for storing ordered data#969mavnn wants to merge 9 commits intoinkle:masterfrom
mavnn wants to merge 9 commits intoinkle:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on one of the proposals in #967 , this PR implements a new
Stackdata type for storing an ordered collection of values. I'm putting it up here as a draft for visibility, especially as I'm not even sure if it is a feature that would be considered valuable for the main Inkle project.Stacks can hold values of any other type, and are not required to be predefined in any way. A stack is initialized using square brackets
[/]and can optionally contain other values. Note that a global stack cannot be initialized with values stored in other variables.Stacks are "immutable" - this means that you cannot add or remove items from a stack in place, but instead you produce a new stack with the value added or removed. They support the equality operator as well as addition and substraction with slightly unusual properties:
To "work through" a stack, we have four native functions. The three pop functions are used to take the newest, oldest, or a random value from the stack while the
STACK_COUNTfunction is used to test whether there any further values to pop.Using these functions, we can also iterate through all the values of a stack if that is useful. This is especially useful in situations where we want to present the player the option to choose one of the values in the stack:
Shows: