Is it possible to implement an integer-to-anytype collection in a language without a builtin collection type?

137 Views Asked by At

I started wondering about this question when I started to dabble with LOLCODE. LOLCODE has 5 data types, YARN (string), TROOF (Boolean), NUMBR (integer), NUMBAR (float), and NOOB (untyped). However, no collection types are provided with version 1.2 of the language, which means no arrays, lists, dictionaries, or any other kind of built-in collection.

For the purpose of challenging myself (and also for the lulz), I decided that I would write in that functionality as a package for LOLCODE, written in LOLCODE. This was much more challenging than I expected, and I’m wondering if it’s even possible for arbitrarily large dynamically sized collections.

Having programmed in C before, I’d used two methodologies for making collections - dynamically sized arrays and linked lists with pointers. However, since LOLCODE has no reference (pointer) type, it’s impossible to use either of these techniques due to there being no way to manipulate memory directly. Machine level approaches won’t work.

Having worked in some functional languages, I started thinking about alternative representations of collections. A collection could theoretically be represented by a function that essentially acts like a switch statement that is dynamically modified on insertion and deletion of elements. However, LOLCODE has no first-class functions either, so this seems impossible as well

The only way I can think of to do this is create n unique variables for a collection of size n - but then the question becomes twofold: “how do I create n unique variables for a collection of size n” and “what happens when the collection expands beyond n elements”?

TL;DR I want to implement arrays in LOLCODE v1.2 and have already spent way too much time thinking about how to do it and have run out of ideas. I just want to know if it’s possible to create an integer-to-anytype collection in a language that doesn’t have it as a builtin - and maybe a hint towards a solution!

0

There are 0 best solutions below