Note that there are some explanatory texts on larger screens.

plurals
  1. POInput in Prolog
    text
    copied!<p>I'm currently working on a recursive Prolog program to link routes together to create a <em>basic</em> GPS of the Birmingham area. At the moment I can get output as so:</p> <p><strong>Input</strong></p> <pre><code>routeplan(selly_oak, aston, P). </code></pre> <p><strong>Output</strong></p> <pre><code>P = [selly_oak, edgbaston, ... , aston] </code></pre> <p>What I would like to do is have my program provide some sort of interface, so if I were to type in something along the lines of:</p> <pre><code>Route from selly_oak to aston </code></pre> <p>It would provide me with:</p> <pre><code>Go from selly_oak to edgbaston Go from edgbaston to ... Finally, Go from ... to aston. </code></pre> <p>Prolog is a powerful language so I assume this is easily possible, however many of the books I've taken out seem to skip over this part. As far as I am aware I have to use something along the lines of write() and read() although the details are unknown to me.</p> <p>Could anyone here a Prolog novice out with some basic examples or links to further information?</p> <p><strong>EDIT:</strong> A lot of these answers seem very complicated, where the solution should only be around 5-10 lines of code. Reading in a value isn't a problem as I can do something along the lines of:</p> <pre><code>find:- write('Where are you? '), read(X), nl, write('Where do you want to go? '), read(Y), loopForRoute(X,Y). </code></pre> <p>I'd prefer it if the output could be written out using write() so a new line (nl) can be used, so that it displays like the output above.</p> <p>If this were my input, how would I then arrange the top routeplan() to work with these inputs? Also, if I were to add the Lines for these stations as an extra parameter how would this then be implemented? All links are defined at the beginning of the file like so:</p> <pre><code>rlinks(selly_oak, edgbaston, uob_line). rlinks(edgbaston, bham_new_street, main_line). </code></pre> <p>Therefore, with this information, it'd be good to be able to read the line as so.</p> <pre><code>Go from selly_oak to edgbaston using the uob_line Go from edgbaston to ... using the ... Finally, go from ... to aston using the astuni_line </code></pre>
 

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