Chain-Based Programming II

Published 2023-06-12


I enjoy the idea of lists. I really like how through code we can create pointers to pointers (or in PICO-8's case, reference to reference). I like experimenting with different simple structures in code and seeing how I can produce different kinds of little graphical effects with them.

This is similar to my Procedural Fire cart, as well as its sister cart, the Cool Sonar Effect. These two carts humor the idea of a command queue, where each entry in the queue is a function which should be called.

Anyway, this cart utilizes singly-linked lists to store string data. There are a few commands which were produced to create a tiny linked-list API. The functions are as follows:

The example code of the cart is:

Notice how in the example code, the characters in the string are added backwards. This is similar to stacking paper, or any kind of stack, really. We have access to only the top item in the stack, and if we want to read it from first to last, we have to add the items in backwards. The link command asks for a reference to the previous link, and returns itself. When used like xxx=link(sub(sss,i,i),xxx) we are storing the most recent link in xxx.

Singly-linked lists (stacks) are not quite as flexible as doubly-linked lists. We cannot read backwards from a stack. Once the topmost item has been removed, we don't have any way to reference it. But, sometimes you don't need that ability. In this example, there isn't even a container object keeping track of things.

One of the more interesting commands of this set is loop(). It asks for the first link, and also a function which will work on each link, starting with the one provided. This can allow you to iterate through each link and do whatever you'd like with its data!

You can even do things like neat mathematical models like the Fibonacci sequence