Comma clause oddness

I’ve seen some built-in constructions in Inform which use commas to add modifying clauses, for example this one from the docs on Lists:

let D be S; remove T from D, if present;
I thought maybe I could do the same thing with my own action. Create a version of the action, then a second version with the comma clause at the end ‘, taking no time’ - to make a non-turn passing version.

For awhile I thought this was working. Eventually I hit weird behaviour in my project, then realised it was because the comma clause thing was silently not working, and the version without any comma was always going to the version WITH the comma.

Here is a demo 1. After ‘test me’, you’d expect the first test to return ‘I danced’ and the second to return ‘I danced and twirled’, but they both return ‘I danced and twirled’.

[rant][code]“Dancing, twirling 1”

Ballroom is a room.

[Test 1]
To dance:
say “I danced.”;

[Test2]
To dance, twirling:
say “I danced, twirling.”;

wanting to run test1 is an action applying to nothing.
Understand “t1” as wanting to run test1.

Carry out wanting to run test1:
dance;

wanting to run test2 is an action applying to nothing.
Understand “t2” as wanting to run test2.

Carry out wanting to run test2:
dance, twirling;

test me with “t1 / t2”.[/code][/rant]
But then!.. I discovered that if I reversed the order these two action definitions appear in the source, the scheme works, as in demo 2:

[rant][code]“Dancing, twirling 2”

Ballroom is a room.

[Test2]
To dance, twirling:
say “I danced, twirling.”;

[Test 1]
To dance:
say “I danced.”;

wanting to run test1 is an action applying to nothing.
Understand “t1” as wanting to run test1.

Carry out wanting to run test1:
dance;

wanting to run test2 is an action applying to nothing.
Understand “t2” as wanting to run test2.

Carry out wanting to run test2:
dance, twirling;

test me with “t1 / t2”.[/code][/rant]
Is this whole thing a bug, or unexpected behaviour that’s slipped through and shouldn’t work at all? Or that should be working but isn’t? I would want to check before thinking about relying on it in any way.

Of course, a safer fix is to just remove the comma.

-Wade

Putting the options all in the same block of code is how I’ve done it. If you have them listed as separate phrases, I wonder if one might override the other?

From §11.14 Phrase options:

To go hiking, into the woods or up the mountain: if into the woods, say "Watch out for badgers."; if up the mountain, say "Better take your compass."; say "You go hiking."

I have the same sense as bg–phrase options go into a single phrase definition. So you could do your thing thus:

To dance, twirling: say "You dance[if twirling], twirling[end if]."

(Assuming you can run the phrase option test in a text substitution, which I haven’t tested.)

I’m guessing the reason it works the second way is that “To dance, twirling” can be called either by “dance” or “dance, twirling,” but “To dance” can only be called by “dance.” So when “To dance, twirling” is called first it preempts the other definition completely, but when it’s defined second, the “To dance” definition traps “dance” but “dance, twirling” has to be caught by the other one.

Thanks both.

-Wade