To fine-tune bg's answer and avoid Joseph Geipel's test cases, I think this should work:
After printing the name of a room while looking:
say " (exits: [list of viable directions])";
definition: a direction (called myd) is viable:
if the room myd of the location of player is nowhere, decide no;
decide yes;
If you need/don't need the exits in another bit of text containing the room name, you should be able to type RULES ON and see which rule fires before printing the room name.