Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

User-question
Hello,

I defined this rule:

"askUser(P) :- write('Yes or no?'), (read(Answer)="yes" -> P=true; P=fail)."

which doesn't work...

I want to ask the User. When he answers "yes" then P should be "true" so
that the rule succeeds. Otherwise it shall fail.

How can I write it correctly?

Thanks,

Marc



Report this thread to moderator Post Follow-up to this message
Old Post
Marc Wamser
10-02-04 08:56 PM


Re: User-question
Marc Wamser wrote:

>
> How can I write it correctly?

Be sure to check the documentation for read/1, and try something similar
to this:

askUser(P) :-
write('Yes or no?'),
read(Answer),
(Answer = "yes" -> P=true; P=fail).

Best regards,
Markus.

Report this thread to moderator Post Follow-up to this message
Old Post
Markus Triska
10-02-04 08:56 PM


Re: User-question
Marc Wamser wrote:
> "askUser(P) :- write('Yes or no?'), (read(Answer)="yes" -> P=true; P=fail)."[/colo
r]

well first, predicates don't return values like functions/functional
procedures in other programming language. so your read(Answer)="yes" is
not a good way (this should always be unsuccessful - matching the record
read(Answer) to "yes" is unsuccessful -> P is matched against fail.

Don't know what implementation you use, but "normal" Prolog
implementation should behave like: read(X) reads a term from the input.
So if you want to match against the string "yes", the user has to type
"yes". If the user just inputs yes. the atom yes is unified with X. The
term has to be closed with a dot. -> 'yes.' instead of just 'yes' has to
be entered by the user.

Some words to style: You could let "askUser" fail if the user answered
with something else than yes.

--
Matthias

Report this thread to moderator Post Follow-up to this message
Old Post
Matthias Kretschmer
10-02-04 08:56 PM


Re: User-question
Hello Matthias,

> The term has to be closed with a dot. -> 'yes.' instead of just 'yes' has
> to be entered by the user.

thanks for your hint.

I tested the example from Markus (see posting below):

askUser(P) :-
write('Yes or no?'),
read(Answer),
(Answer = "yes" -> P=true; P=fail).

Now I tried it with "askUser(X)" and then I answered "yes." (with the dot
;) ).

But the answer is still "X = fail?"... Why?

Marc



Report this thread to moderator Post Follow-up to this message
Old Post
Marc Wamser
10-02-04 08:56 PM


Re: User-question
Marc Wamser wrote:

>
> I tested the example from Markus (see posting below):
>
> askUser(P) :-
> write('Yes or no?'),
> read(Answer),
> (Answer = "yes" -> P=true; P=fail).

Sorry, you have to remove the quotes from "yes" (yes). Otherwise, it is
treated a a list of latin1-characters.

Best regards,
Markus.

Report this thread to moderator Post Follow-up to this message
Old Post
Markus Triska
10-02-04 08:56 PM


Re: User-question
Thank You.

/Marc



Report this thread to moderator Post Follow-up to this message
Old Post
Marc Wamser
10-03-04 01:56 AM


Re: User-question
Marc Wamser wrote:
> Hello,
>
> I defined this rule:
>
> "askUser(P) :- write('Yes or no?'), (read(Answer)="yes" -> P=true; P=fail)
."
>
> which doesn't work...
>
> I want to ask the User. When he answers "yes" then P should be "true" so
> that the rule succeeds. Otherwise it shall fail.
>
> How can I write it correctly?
>
> Thanks,
>
> Marc
>
>

Maybe it is more a question of describing the kind of situation that
you have in mind, as in,

user_said_yes_or_no(X) :-
repeat,
write('Please type in 'yes' or 'no' followed by '.' : '),
read(X),
yes_or_no(X),
!,
nl,
write('Thank you'),nl.

yes_or_no(yes).
yes_or_no(no).

--
billh

Report this thread to moderator Post Follow-up to this message
Old Post
student
10-04-04 01:39 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Prolog archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:53 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.