Adding stacks to Ink

I’ve only really missed one feature in Ink for general narrative development, which is ordered collections. So I added them as a compiler plugin!

LIST qualities =
  strength, skill, control, 
  speed, honour

STACK sensei_values 3 strength

~sensei_values_push(strength)
~sensei_values_push(skill)
~sensei_values_push(honour)

// Oops, sensei had a change of heart
~sensei_values_set(3, speed)

Sensei values {sensei_values_index(1)}, {sensei_values_index(2)}, <>
{sensei_values_index(3)}.

// Outputs: Sensei values strength, skill, and speed.

I understand why Ink doesn’t have complex state management features given how it is used by Inkle, but this still seems like a generally useful enough concept that I thought I’d share. More details in a blog post: Stacks in Ink

4 Likes

Since this post, I decided it was actually worth going the ‘whole hog’ and at least experiment with adding stacks to the runtime rather than via code gen.

I’ve blogged about the results with a bunch of examples, and I’m pretty happy with the outcome. If you’ve been looking for ways to include prioritization or limited resources like magic runes in Ink, you might find this interesting. Important note: none of this is part of ‘official’ Ink yet, and it may not ever be as it doesn’t fully fit Ink’s normal role as an ‘embedded’ language. But I decided to implement it anyway as it does make sense for my particular use of Ink, so I thought I’d share.

Neat.

I love Ink, but I have to admit that I’ve frequently wished for a bit more programming/script language features in it. A lot of less ideal choices made in the design, from a language-design point of view. Even built my own Ink compiler at one point, with some of the features I felt were missing.

Nowadays, I just use external functions for most of this stuff. It does mean that scripts tend to be a function heavy (and external functions have their own issues, which require some finessing), but overall I’ve found it preferable from a maintenance point of view.

Might be different now, I suppose, since they no longer change things very often.

1 Like

I implemented stacks in pure Ink once. Mostly good for if you want to see some really cursed runtime efficiencies. Have you ever seen a stack where pop has efficiency O(MAX_INT*n^2)? Well, now you have!

2 Likes