Finally we come to the second part of the program. The search is complete and the database is full of statements about how it proceeded. To trace out the route is now straightforward, since with each arrival was recorded the previous location of the group. Thus a call to present with a pattern incorporating the name of a location will reveal the point from which it was reached -- for example,
present([arrived ^place at ?time mins from ?lastplace]);
Successive values of place and time are stored in a list, beginning with the destination and continuing back until lastplace is the start station. When reversed, the list gives the route. The main procedure, route, which returns the list of stations, can be called from within answer:
define answer(query)->response; vars x; if query matches [how do i get to ??x] then route([victoria],x)->response; elseif ... endif; enddefine; answer([how do i get to marble arch])=> ** [[[VICTORIA victoria] at 0 mins] [[VICTORIA green park] at 2 mins] [[VICTORIA oxford circus] at 4 mins] [[CENTRAL oxford circus] at 7 mins] [[CENTRAL bond street] at 9 mins] [[CENTRAL marble arch] at 11 mins]]
All that remains is to convert this information into a form suitable for printing out to the real traveller, standing on the platform and looking at the screen, unaware that his or her route has been planned by the combined efforts of a myriad of simulated explorers!