Re: Simply Expert System for Visual Prolog



On Tue, 28 Jun 2005 17:12:19 +0200
metah <bisgmbh@xxxxxxxxxxx> wrote:


>
> Hi,
>
> the problem is, I cannot make my visual prolog to read any chars from
> the keybord (it reads but I can't work with that)
>
> example in PIE:
>
> dupa():- write("Yes or No ? "),
> repeat,
> readchar(Char),
> (
> member(Char,[`y,`Y]), Answer = yes ;
> member(Char,[`n,`N]), Answer = no
> ),
> write(Answer),nl.
>


This needs a cut to prevent backtracking after a unification (say, with 'Y').
But that boges your repeat loop. So you should refactor this.

Say you want it to repeat reading the keybord till break or forever.

One formulation for this in Prolog is repeat, 1,2,3,4,5, fail. and if there's no cut between
repeat and fail, the sequence of instructions, 1,2,3,4,5 will be repeated endlessly.

You can make the failure condition less absolute, as in ..5, member(Char,[`q,`Q]), ... which will only
succeed if you have typed a Q or q.

Given these are your requirements, you want something that looks like the following:

dupa:-
write('Yes or No ?' ), %initial prompt
repeat, %repeat is like the paddle to which a rubber ball is tied
get_char(Char), %Get the ball
dupa2(Char),!. %bounce it,

%and see if it comes back...
dupa2(Char):- member(Char,['y','Y']),write('yes'),nl,!,fail. %yes we failed to break the rubber band
dupa2(Char):- member(Char,['n','N']),write('no'),nl,!,fail. %no we failed to break the rubber band
dupa2(Char):- member(Char,['q','Q']),write('Quit'),!. %Quit means we succeed on this bounce
dupa2(Char):- char_code(Char,10),write('Yes or No ?' ),!,fail. %Reprompt on the newline because I'm using Gprolog/UNIX and it's line io

dupa2(_):- !,fail. %everything else bounces back to the repeat as well -- this clause doesn't need to be here

Dhu



>
> it doesn't work - if I press Y or y / N or n - I become no results - I
> should get "YES" or "NO".
>
> Why?
>
> thx
>
> -----------
> y
> Trace: >> RETURN: readchar(y)
> Trace: >> CALL: member(y,[y,Y])
> Trace: >> FAIL: member(y,[y,Y])
> Trace: >> CALL: member(y,[n,N])
> Trace: >> FAIL: member(y,[n,N])
> Trace: >> REDO: readchar(y)
> Trace: >> FAIL: readchar(_)
> Trace: >> CALL: readchar(_)
>
> -------------
>
> Duncan Patton wrote:
> > I don't have any Turbo Prolog code around any more, but that's what you need to
> > look for. There's a whole bunch of examples came with the releases and these
> > should work under VP with minor modification.
> >
> > Dhu
> >
> > On Sun, 26 Jun 2005 18:24:50 +0200
> > metah <bisgmbh@xxxxxxxxxxx> wrote:
> >
> >
> >>Hi,
> >>
> >>does anybody know, where could I download a simple expert system for
> >>Visual Prolog? Some Rules, Some Questions and then one Solution - thats it.
> >>
> >>I have downloaded some systems, but they don't work under visual prolog.
> >>
> >>Thanks
> >>
> >>metah
> >>
> >>metah@xxxxxxxxxxxxxxxxx
> >
> >
> >


--
???????????????????????????????????????

Can't get good help?

Contact Fubar the Hack: fubar AT neotext.ca

Area code seven eight zero, Exchange four six six, Local zero one zero nine

Highland terms, Canadian workmanship.

All persons named herein are purely fictional victims
of the Canidian Bagle Breeder's Association.

Save the Bagle!

Sun Ðhu

???????????????????????????????????????


.