User interface I/O

From: bex145 (becca25_99_at_yahoo.co.uk)
Date: 04/27/04


Date: Tue, 27 Apr 2004 09:19:05 -0400

Hi i am writing a route calculator program in prolog and i am having
difficulty with the user interface.

i need to query the user where they wish to go. i can get that to work and
read in the input and then use it in a predicate but when i want to use
that input again in another predicate it is lost and does not have
anything assigned to it. I also want to check that the input is correct
that the destination exists and i have done that a long way around i
think?

I also get errors when consulting saying i have singleton variables. has
anyone got any suggestions on my code for a suitable user interfaces how
to do them properly- where you can check input and use the input terms
again or assign them. i have been trying to get this to work for weeks so
any help would be much appreciated.

excert from my code:

:- write('Welcome to the Tripfinder'),
        tripfinder.

tripfinder:-
        nl,
        write('Where are you traveling from?'),
        nl,
        read(A),
        try(A).
        
        again:-
        write('Where are you going to?'),
        nl,
        read(B),
        process(A,B).

try(london):-
        again.
try(guilford):-
        again.
try(downtown):-
        again.
try(exworth):-
        again.
try(glastoby):-
        again.
try(dabton):-
        again.
try(tinville):-
        again.
try(Other):-
        write('Sorry your destination was not recognised'),
        nl,
        write('please try again.'),
        tripfinder.
        
process(A,B):-journey(A,B,DIST,ROUTE),
        write('The route found is'), write(ROUTE),
        nl,
        write('The distance is '), write(DIST), write(' miles'),nl,
        write('Would you like a list of all possible routes?'),nl,
        read(Z),
        check(Z),
        tripfinder.

printlist([First|Rest]):-
        N is 1,
        write(N),
        write(' Dist Miles: '),
        write(First),
        N is N + 1,
        printlist(Rest),
        nl.

check(no):-
        !.

check(yes):-findall((DIST,ROUTE),journey(A,B,DIST,ROUTE),List),
        printlist(List),
        nl,
        write(DIST),
        nl,
        write(ROUTE).
        
check(Z):-
        write('please respond yes or no'),
        nl,
        read(Y),
        check(Y).

:-use_module(library(lists)).

road(london,guilford,5).
road(guilford,exworth,30).
road(guilford,glastoby,30).
road(guilford,dabton,25).
road(downtown,exworth,20).
road(downtown,glastoby,40).
road(downtown,tinville,15).
road(glastoby,tinville,30).
road(exworth,dabton,10).
road(exworth,tinville,10).

trip(A,B,DIST):-
        road(A,B,DIST).
trip(A,B,DIST):-
        road(B,A,DIST).

journey(A,B,DIST,ROUTE):-
        journey(A,B,DIST,ROUTE,[]).

journey(A,B,DIST,ROUTE,BEENTHERE):-
        trip(A,B,DIST),
        \+ member(B,BEENTHERE),
        ROUTE = [A,B].

journey(A,B,DIST,ROUTE,BEENTHERE):-
        trip(A,PLACE,ADIST),
        \+ member(PLACE,BEENTHERE),
        journey(PLACE,B,BDIST,VISITED,[A|BEENTHERE]),
        ROUTE = [A|VISITED],
        DIST is ADIST + BDIST.
        

also i need to work out the shortest route and i can do that using the </1
predicate but i am unsure as to how i can compare two DIST values in two
results- how to check and store them. any help will be greatly
appreciated.

cheers



Relevant Pages

  • Re: maximum records in form view
    ... Form view are different formats for the user interface; ... in tables that you can open from the database window (the box that shows up ... query that doesn't return all the rows or it has a filter applied. ... you get all expected rows then the form must have a filter aplied to it. ...
    (microsoft.public.access.gettingstarted)
  • Re: Build A Query With Criteria Of Many
    ... Can we begin by specifying a User Interface on which this could run? ... The query must filter by these names. ... This can be done by filtering with the INclause ... Any store that has all the desired ...
    (microsoft.public.access.queries)
  • Re: Micorsoft Jet does not recognize forms!form1!Calendar0 as a valid feild name or expression
    ... You are accessing the data through the User Interface? ... The syntax FORMS!FormName!ControlName is only acceptable from the User ... If you access a saved query, ... Query 1 - SQL ...
    (microsoft.public.access.forms)
  • Re: Very slow query
    ... reports fall into the user interface category; the focus here is on making ... in a query, add the "secondary" tables that are needed so that you can ... Alain T. ... simplify writing a query to show the "display" data from secondary ...
    (microsoft.public.access.queries)
  • Re: Grouping record I need help NOW!!!!!
    ... If a query, please post back with the SQL view of the query. ... Steve Schapel, Microsoft Access MVP ... > it is already open through the user interface and cannot be ... > that on the tools menu I have the the default open mode to "shared". ...
    (microsoft.public.access.forms)