Elegant way to test whether something is in a location (even if in a container)

While we’re on the topic of what could kindly be termed ‘idiosyncracies’ in Inform, others have previously expressed frustration at the bizarre way that ‘includes’ for snippets is equivalent to ‘matches’ for texts, while ‘matches’ for snippets is equivalent to ‘exactly matches’ for texts- in phrases such as 'if the player’s command matches “take aardvaark”, replace the matched text with “take anteater”.

This can be fixed by adding the following to source text, which also adds phrases to allow the negation of conditions matching regular expressions to texts:

To decide if (s - a snippet) matches (t - a topic):
	if s includes t, yes;
	no.
To decide if (s - a snippet) does not match (t - a topic):
	if s includes t, no;
	yes.
To decide if (s - a snippet) exactly matches (t - a topic):
	if s includes t :
		if the matched text is s:
			yes;
	no.
To decide if (s - a snippet) does not exactly match (t - a topic):
	if s does not include t :
		yes;
	if the matched text is not s:
		yes;
	no.
[these phrases align the syntax for matching snippets to that for matching texts- ordinarily 'matches' for snippets == 'exactly matches' for texts, and 'includes' for snippets=='matches' for texts]
To decide if (t - a text) does not match the regular expression (r - a text):
	if t matches the regular expression r, no;
	yes.
To decide if (t - a text) does not exactly match the regular expression (r - a text):
	if t exactly matches the regular expression r, no;
	yes.
[this is a syntax inexplicably missing from Inform- without these phrase definitions compiler will throw an error as it tries to set up a match between a snippet and a topic (as in 'the player's command does not match "room [number]") rather than a text with a text, not helped by the absence of a logical 'not' in complex conditional phrases- so we can't say 'if X and not Y ...' or even 'if X and unless Y...']

4 Likes