- Common Loki Misconfigurations
- Iterating Through a List in Ink
- Debugging Misconfigured Container Networks
- Minimum Viable EC2 in Terraform
- Storylets in Ink
- Interactive Fiction Tooling Overview
- In-Place Resizing for Digitalocean Droplets
- Unity Demonstrates the Importance of FOSS
- Target Labels in Prometheus
- My View of AI is the Same
- Verify DNS Ownership with TXT Records
- Sane Droplet Defaults
- Editing Made Easy with Vim
- Gatsby Gotchas
- Concatinating Default AWS Tags in Terraform
- Easily Updating the Default Github Branch
- Lifetimes in Rust
- Checking for Bad Links
- Maybe TypeScript and React is Bad
- Static Asset Management in React
- Bundler Down Time
- Using React Context for Localization
- JS Implementation of a Sticky Footer
- Custom Aliases
- Trying Out the 7drl Challenge
- Trash Opinions
- Building Your First Program in Rust
- Fixing mongod reports errors related to opening a socket
- Improving Open Source Maintenance
- Technical Interviewing Tips
- Housekeeping Note
- Dynamic Programming Basics
- The Oddity of Naming Conventions in Programming Languages
- An Experiment Using Machine Learning, Part 3
- Debugging with grep
- An Experiment Using Machine Learning, Part 2
- An Experiment Using Machine Learning, Part 1
- The Value of while
- National Day of Civic Hacking
- OpenAI and the Future of Humanity
- Creating a Whiteboard App in Django
- Creating Meaningful, Organized Information
- Towards A Critique of Social Media Feeds
- Setting up Routes in Django
- Developing a Messaging Component for Code for SF
- Dream Stream 2.0
- Keyed Collections in Javascript: Maps and Sets
- Blog Soft Relaunch
- Scraping with Puppeteer
- Looking Ahead to Dream Stream 2.0
- Solving West of Loathing's Soupstock Lode Puzzle
- Installing Ubuntu
- Interview with David Jickling Evaluation
- Compare Text Evaluation
- Dream Stream Evaluation
Iterating Through a List in Ink
Ink’s lists are not an array like in Python. Instead they are boolean sets. They are mostly used for activating and deactivating certain elements within the set, or perhaps incrementally moving along the elements of the set. As such, Ink’s list lacks a lot of the functionality you would expect from an array, including pushing and popping elements, or iterating through the list.
However, since recursion is possible in Ink, it is still possible to iterate through a list with the caveat that there is some unexpected behavior that will throw up an error if you attempt an obvious implementation, as we will see below. This is how you might first attempt it:
=== function list_iteration(l, i) ===
~ temp length = LIST_COUNT(l)
{l(i)}
{i < length:
~ i += 1
~ list_iteration(l, i)
}
The function takes the list, and the initial integer value as its parameters, prints the content, and then if i
is less than the length value of the list, increments i
and calls the function again.
Unfortunately, if you write this code in Inky, it will throw up the following error: since 'l' is used as a divert target... it should be marked as -> l
. Needless to say, l is not a divert target, and if you try to implement the suggested change, it will not work. I believe this is an implementation bug.
At present, we can work around this bug by reducing an abstraction, and not calling the list itself as a parameter. This makes our code less DRY if there are multiple lists that you need to iterate through, but since the alternative is a program that won’t execute that is the price you have to pay. The code below works for a list called Numbers
:
LIST Numbers = (one), (two), (three), (four)
=== function number_iteration(i) ===
~ temp length - LIST_COUNT(Numbers)
{Numbers(i)}
{i < length:
~ i += 1
~ number_iteration(i)
}
Calling number_iteration(1)
returns:
one
two
three
four