IO 3 - 08_IO 13 Another Example Read in characters, write...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Reading English Sentences (cont.) Same as previous example, but don’t write out ‘.’: go :- do_a_char, go. do_a_char :- get_char(X), X= '.', !, fail. do_a_char :- put_char(X). :- go. I am feeling great. Error! put_char argument not instantiated! York University- CSE 3401- V. Movahedi 08_IO 11
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Reading English Sentences (cont.) How about this code? go :- do_a_char, go. do_a_char :- get_char(X), X= '.', !, fail. do_a_char :- get_char(X), put_char(X). :- go. I am feeling great. mfeigget Once a character has been read from the terminal, if not saved, it will be gone forever, can never get hold of it again! York University- CSE 3401- V. Movahedi 08_IO 12
Background image of page 2
Reading English Sentences (cont.) Get hold of the character: go :- get_char(X), get_more(X). get_more (‘.’) : - !, fail. get_more(X) :- put_char(X), get_char(Next), get_more(Next). :- go. I am feeling great. I am feeling great York University- CSE 3401- V. Movahedi
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 08_IO 13 Another Example Read in characters, write them out again, until a . is read. Convert as to As. Convert . to !. go :- get_char(X), get_more(X). get_more (.) :- !, put_char (!), fail. get_more(a) :- !, put_char (A) , get_char(Next), get_more(Next). get_more(X) :- put_char(X), get_char(Next), get_more(Next). :- go. I am feeling great. I Am feeling greAt! York University- CSE 3401- V. Movahedi 08_IO 14 Read/Write Files Input streams Keyboard Prolog name: user_input , It is the default input stream A file (opened for reading) Output streams Display Prolog name: user_output It is the default output stream A file (opened for writing) The same predicates can be used for file streams: read, write, get_char, put_char, nl York University- CSE 3401- V. Movahedi 08_IO 15...
View Full Document

Page1 / 5

IO 3 - 08_IO 13 Another Example Read in characters, write...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online