When writing grammars, you can use Inform 7 built-in functions to dynamically list contents or check object states.
Listing Contents
Use [a list of things in the <object>] for containers or [a list of things on the <object>] for supporters. This ensures the description updates automatically as items are moved.
Example:
The chest has [a list of things in the chest] in it.On the shelf [is-are a list of things on the shelf].
Conditional State Descriptions
You can use [if x is open][else if x is locked][otherwise][end if] to modify sentences based on an object's state (open, locked, or closed).
Example:
The chest is [if chest is open]open[else if chest is locked]locked[otherwise]closed[end if].
# Containers
In the chest [is-are a list of things in the chest]. -> In the chest are a pen and an apple.
The chest has [a list of things in the chest] in it. -> The chest has a pen and an apple in it.
# Supporters
On the shelf [is-are a list of things on the shelf]. -> On the shelf are a pen and an apple.
The shelf has [a list of things on the shelf]. -> The shelf has a pen and an apple in it.
# State checking
The chest is [if chest is open]open[else if chest is locked]locked[otherwise]closed[end if].