Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree with your initial impulse in thinking that using a number of module files would be best. I imagine that one reason for using different files would be to provide different name spaces for facts and rules which would be best expressed using the same predicates. So that, for instance, <code>Description</code> would be different for <code>room(1, Description)</code> in mission 1 than in mission 2.</p> <p>One way of achieving this would be by accessing private, non-exported predicates in each of the different mission-modules. (<em>Aside</em>: I read Jan Wielemaker caution against this practice somewhere, but I'm not sure why, nor am I sure that I did read this.)</p> <p>Here's a possible pattern I threw together:</p> <p>Given a main file, 'game.pl', with the following program,</p> <pre><code>:- use_module([mission1, mission2]). start :- playing(mission1). playing(CurrentMission) :- read(Command), command(CurrentMission, Command), playing(CurrentMission). command(_, quit) :- write('Good bye.'), halt. command(CurrentMission, Command) :- ( current_predicate(CurrentMission:Command/_) % Makes sure Command is defined in the module. -&gt; CurrentMission:Command % Call Command in the current mission-module ; write('You can\'t do that.'), % In case Command isn't defined in the mission. ). </code></pre> <p>and these mission modules,</p> <p>In file 'mission1.pl':</p> <pre><code>:- module(mission1, []). turn_left :- write('You see a left-over turnip'). eat_turnip :- write('You are transported to mission2'), playing(mission2). % Return to the prompt in `game` module, but with the next module. </code></pre> <p>In file 'mission2.pl':</p> <pre><code>:- module(mission2, []). turn_left :- write('You see a left-leaning turncoat.'). </code></pre> <p>Then we can play this shitty game: </p> <pre><code>?- start. |: turn_left. You see a left-over turnip |: eat_turnip. You are transported to mission2 |: turn_left. You see a left-leaning turncoat. |: quit |: . Good bye. </code></pre> <p>The specifics of this program are problematic for a number of reasons. For instance, I expect we might rather have a single predicate that handles navigating through places, and that we'd rather describe places and object that react to different commands in our missions, rather than account for every possible command. But the general principle of using the different files would still work.</p> <p>Another approach would be to use <code>consult/1</code> and <code>unload_file/1</code> to load and unload modules, in which case you should be able to use their public, exported predicates instead of calling them by module. Documentation for those and related predicates can be found in the manual in the section <a href="http://www.swi-prolog.org/pldoc/man?section=consulting" rel="nofollow">"Loading Prolog Source Files"</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload