Parsing the serial comma

Regardless of whether you use the option ‘Use the serial comma’ or not, Inform will parse these commands:

[code]>take A, B, C

take A and B, C
take A, B and C
take A and B and C[/code]
but not this one:

>take A, B, and C

Which is, as far as I can tell, because it thinks that the third item on the list is something called ‘and C’. I’d never enter a command like this (for which I’d like to thank my parents, Ayn Rand and God), but a substantial number of my American testers – including experienced IF players – do it this way first, sometimes assuming that if that doesn’t work for a given verb, that verb won’t work on multiple objects.

I’m guessing that the way around this would involve tampering with the player’s command; is replacing “, and” with “,” going to cause problems in some other legitimate command phrasing that’s not occurring to me?

This is a feature request – and I’d say it ought to be given a high priority. There is simply no way that a command in that form should fail to be understood.

Here’s a test output:

I can’t think of any pitfalls there. Go for it.

Bug or feature request, it’s been in the Inform parser for nearly twenty years. (I just tested Curses.) I think this is the first I’ve heard of it. Maybe we could call it a medium-high priority.

How about this farcical hack?

[code]Idempotence relates a thing (called X) to a thing (called Y) when X is Y. The verb to be idempotent with implies the idempotence relation.

Understand “and [something related by idempotence]” as a thing.[/code]

(I realize that’s not really what idempotence is.)

Yeah. The only reason that it’s coming up at all is that this particular game has a relatively high number of multiple-object verbs, which the player will use a lot, but not necessarily with ALL. If I’m doing weird things with I7, I expect to have to do weird fixes.

…except that you can’t do this with

if the player's command includes ", and" begin; replace the matched text with ","; end if;
because you’re not allowed to use ‘understand’-type phrases with anything containing punctuation that’s already used by the parser (.,!?::wink:

If you could replace the player’s command with an indexed text, I’d suggest using regex, but Inform doesn’t like that either.

This is the old-fashioned way of doing it:

Include (- 
[ SquashSerialAnd
	ix jx lastwd wd addr len changedany;
	for (ix=1 : ix<= num_words : ix++) {
		wd = WordFrom(ix, parse);
		if (lastwd == comma_word && wd == AND1__WD) {
			addr = WordAddress(ix);
			len = WordLength(ix);
			for (jx=0 : jx<len : jx++) {
				addr->jx = ' ';
		lastwd = wd;
	return changedany;

To squash serial ands:
	(- if (SquashSerialAnd()) { 
		num_words = WordCount();
		players_command = 100 + WordCount();
	}; -)

After reading a command:
	squash serial ands.

And that works a treat. Thank you very much, sir.

Why can’t you just do this?


After reading a command (this is the strip serial comma rule):
if the player’s command matches the text “, and” begin;
let comma be indexed text;
let comma be the player’s command;
replace the regular expression “, and” in comma with " and";
change the text of the player’s command to comma;
end if.

The Testing Room is A Room. A peach, a plum and a banana are in the testing room.

Test me with “take peach, plum, and banana / drop peach, plum, and banana”.[/code]

This seems to work fine.

Well, from what I recall, something is idempotent if and only if any positive exponent of it is zero.

The usual term is “the identity relation”.

Yeah, but I was afraid that “identity” was either reserved in I7 somehow or that someone might want to use it elsewhere in the code; I wanted to use a name that I was pretty sure wouldn’t result in namespace clashes.

Is there another way to do the thing I was doing?

(climbingstars – idempotence can mean somewhat different things in different contexts, but for instance an idempotent function is one such that f(x) = f(f(x)) for every x. Multiplying by zero is idempotent because no matter how many times you do it it comes out zero.)

I’m not sure I want to think about the thing you were doing. Best to leave it as it is, possibly with a clown-hat on it so that people will have fair warning…