Listing Non-Objects

Inform has a very elaborate built-in list writer, for printing lists of objects in various ways. But its degrees of customization mostly come down to how those objects are arranged and formatted. If you want to list something other than the printed name, for example, or any kind of value that’s not an object, you’re out of luck.

Previously, I’d just worked around this by putting together my other sorts of lists manually. But when zarf posted the Hadean Lands source for SCAD, I noticed an interesting snippet:

To say cheap list (T - object) with (M - text): (- cheaplist_entry({T}, {M}); -).

He used text as a callback for his custom list-writer, to print things other than the printed name! This gave me an idea.

So behold, a new way of printing lists:

Include (-
Global listing_parameter;
-).
To decide which K is the (name of kind of value K) being listed: (- listing_parameter -).
To set the (name of kind of value K) being listed to (V - K): (- listing_parameter = {V}; -).
To push the listing parameter: (- @push listing_parameter; -).
To pull the listing parameter: (- @pull listing_parameter; -).

To print a/the/-- list of (T - text) for (D - description of values of kind K), prefacing with is/are and/or disjunctive:
	let N be the number of D;
	if prefacing with is/are:
		say "[if N <= one]is[else]are[end if] ";
	if N is zero:
		say "nothing";
		stop;
	let J be 1;
	push the listing parameter;
	repeat with V running through D:
		set the K being listed to V;
		say T;
		if J is N: [Final one]
			next;
		else if J is N minus 1: [Second-to-last]
			if N > 2 and the serial comma option is active: [Only print a serial comma if there are three or more items]
				say ",";
			say " [if disjunctive]or[else]and[end if] ";
		else: [Any other]
			say ", ";
		increment J;
	pull the listing parameter.

The crucial phrase is “print the list of (text) for (description of values)”. The text is what should be printed for each value matching the description. This means that you can print a list of values that aren’t objects: you could print the list of “numbers the player remembers”, for example, or “spells inscribed in the grimoire”.

If you want to print something other than just the name of the value, that’s what the text is for! For instance, the text could be “[the number being listed times two]”, or “[the description of the spell being listed]”, or “[the spouse of the person being listed]”. In other words, this phrase also lets you make a list of objects that displays something other than the printed name.

Does this seem useful to others? If so, I’ll throw it into an extension once it’s gotten a bit more testing.

Finally, here’s a specific example:

Position is a kind of value. The positions are defined by the Table of Positions.

Table of Positions
position	name
null-position	"ERROR - REPORT THIS"
inside-position	"inside"	
above-position	"on top of"
below-position	"underneath"
behind-position	"behind"

Understand "in" or "inside of/--" as inside-position.
Understand "on/over/above" or "on top of/--" as above-position.
Understand "under/underneath/below" as below-position.
Understand "behind" as behind-position.

Concealment potential relates various things to various positions. The verb to allow concealment in means the concealment potential relation. The verb to be allowed by means the reversed concealment potential relation.

Definition: a thing is a hiding place if it allows concealment in a position.

After examining a hiding place:
	say "[We] [could] probably fit ";
	print a list of "[name of position being listed]" for positions that are allowed by the noun, disjunctive;
	say " [regarding the noun][them], if [we] needed to hide.";
	continue the action.
3 Likes

To be clear, I was also “putting together my lists manually”! As in your code, I banged together the commas and “and” by hand.

(I like your use of push/pull with a global. I see my code used “substitution-variable”, an undocumented I7 global that went out with 6G60. Had to look that one up…)

2 Likes

True, but you did make a general-purpose phrase that handles the commas and “ands” for the general case! That’s the part I was getting tired of replicating over and over every time I used it.

I’ve (re)invented this myself a few times, so an extension would be appreciated by me, at least!

1 Like