Am I right? 
Author Message
 Am I right?

In Prolog, there is no way to:

Prompt the user to type a string (including spaces) on screen and get it
after the user press Return (not require ".").

Am I right?

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sat, 02 Nov 2002 03:00:00 GMT  
 Am I right?

Quote:

>In Prolog, there is no way to:

>Prompt the user to type a string (including spaces) on screen and get it
>after the user press Return (not require ".").

>Am I right?

I hope not :-)  read/1 reads Prolog-terms.  To read anything else you need
to use one of the character-reading predicates.  These are:

        get0            Good old Prolog
        get_code        ISO Prolog: read character code
        get_char        ISO Prolog: read one-character atom.

For the good old Prolog (runs on most systems, but nowadays I would use
the ISO versions):

read_line(Line) :-
        read_line(user_input, Line).

read_line(S, Line) :-
        get0(S, C0),
        read_line(C0, S, LineChars),
        name(Line, LineChars).          % or atom_codes or just leave it a string

read_line(10, _, []) :- !.              % \n
read_line(13, _, []) :- !.              % \r
read_line(C0, S, [C0|T]) :-
        get0(S, C1),
        read_line(C1, S, T).

        Regards --- Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jan Wielemaker                Author of SWI-Prolog and the XPCE GUI library
SWI, University of Amsterdam  http://www.swi.psy.uva.nl/projects/SWI-Prolog/



Sat, 02 Nov 2002 03:00:00 GMT  
 Am I right?

Quote:

> In Prolog, there is no way to:
> Prompt the user to type a string (including spaces) on screen and get it
> after the user press Return (not require ".").
> Am I right?

no you're wrong. Check your manual for get/1 in order to read character
by character.

--
Gertjan van Noord Alfa-informatica, RUG,  Postbus 716, 9700 AS Groningen
vannoord at let dot rug dot nl            http://www.let.rug.nl/~vannoord/



Sat, 02 Nov 2002 03:00:00 GMT  
 Am I right?

Quote:
> >Am I right?

> I hope not :-)

I hope not too :-)

I have just tried your code (thanks to you), when I typed a+b, I got
'a+b'....How to make sure I get the same as the input? I need a+b
instead of 'a+b' :-(

Cheers.

Sent via Deja.com http://www.deja.com/
Before you buy.



Sat, 02 Nov 2002 03:00:00 GMT  
 Am I right?

Quote:

>> >Am I right?

>> I hope not :-)

>I hope not too :-)

>I have just tried your code (thanks to you), when I typed a+b, I got
>'a+b'....How to make sure I get the same as the input? I need a+b
>instead of 'a+b' :-(

What did you want? Reading terms or reading text. read/1 is for terms,
the read_line/[1,2] I gave you is for text. If you insist reading a
Prolog term that is newline delimited instead of '. ', you can convert
the read text into a term. This is not standard Prolog. SWI-Prolog
defines atom_to_term/3. Some others (sicstus, quintus) have
with_input_from_chars/2, etc. Check your manual.

        Regards --- Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jan Wielemaker                Author of SWI-Prolog and the XPCE GUI library
SWI, University of Amsterdam  http://www.swi.psy.uva.nl/projects/SWI-Prolog/



Sun, 03 Nov 2002 03:00:00 GMT  
 Am I right?

Quote:
> >I have just tried your code (thanks to you), when I typed a+b, I got
> >'a+b'....How to make sure I get the same as the input? I need a+b
> >instead of 'a+b' :-(

> What did you want? Reading terms or reading text. read/1 is for terms,
> the read_line/[1,2] I gave you is for text. If you insist reading a
> Prolog term that is newline delimited instead of '. ', you can convert
> the read text into a term. This is not standard Prolog. SWI-Prolog
> defines atom_to_term/3. Some others (sicstus, quintus) have
> with_input_from_chars/2, etc. Check your manual.

Thank you so much.

I didn't know how to explain :-( Now I think what I need is to read a
term delimited with newline. I am going to compile my program into an
exe file for the users who don't know Prolog at all.
Does SWI have something like read_term(Term, delimition=10)?

Cheers.

Quote:

>    Regards --- Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
Quote:
> Jan Wielemaker                Author of SWI-Prolog and the XPCE GUI
library
> SWI, University of Amsterdam

http://www.swi.psy.uva.nl/projects/SWI-Prolog/

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 03 Nov 2002 03:00:00 GMT  
 Am I right?
Try this!!

readString(Cad) :-  readStr(List),
   string_to_list(Cad,List).

readStr(String) :-  get0(Char),
   (Char=10 ->
    String=[]
   ;
    readStr(List),
    String=[Char|List]
   ).

Pablo.



Tue, 12 Nov 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. VO my understanding,am I right?

2. Am I Right?

3. Am I on the right track?

4. Am I on the right track?

5. Reverse Engineering Continued (Am I on the right track)

6. Am I on the right track?

7. Canvas: Am I headed in the right direction?

8. Right, left, Right.

9. Update on what happens to data to the right of the right margin

10. I am not deaf, but am I mute?

11. New to Clarion 4b - Am I in the right newsgroup?

12. Adding compressed Palm pixmap format to PIL; am I on the right track?

 

 
Powered by phpBB® Forum Software