IO 2 - York University- CSE 3401- V. Movahedi 08_IO 8...

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

View Full Document Right Arrow Icon
WRITE (cont.) Examples :- write ([‘Hello’, world]). [Hello, world] true. :- X is 4+4, write(X). 8 X=8. :- write(X). _G248. true. York University- CSE 3401- V. Movahedi 08_IO 6
Background image of page 1

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

View Full DocumentRight Arrow Icon
Vine diagram (pretty print) Indentation for nested lists pp([1, [2,3], [4, [5]], 6], 0) spaces(0) :- !. spaces(N) :- write(' '), N1 is N -1, spaces(N1). pp([H|T], I) :- !, J is I+3, pp(H, J), ppx(T, J). pp(X, I) :- spaces(I), write(X), nl. ppx([], _). ppx([H|T], I) :- pp(H, I), ppx(T, I). York University- CSE 3401- V. Movahedi 08_IO 7 1 2 3 - 4 5 6
Background image of page 2
Printing lists :- write([‘Good’, morning, ‘!’]). [Good, morning, !] Write a list w/o the commas and [] :- phh ([‘Good’, morning, ‘!’]). Good morning ! phh([]):- nl. phh([H|T]) :- write(H), spaces(1), phh(T).
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: York University- CSE 3401- V. Movahedi 08_IO 8 Read/Write characters get_char(X) Similar to read, but reads only one character Press Enter after input, so it will be available to Prolog put_char(X) Similar to write, but writes only one character Example: :- get_char(X), put_char(X). M entered by user M X = M. York University- CSE 3401- V. Movahedi 08_IO 9 Reading English Sentences Read in characters, write them out again, until a . is read: go :- do_a_char, go. do_a_char :- get_char(X), put_char (X), X=., !, fail. do_a_char . :- go. I am feeling great. I am feeling great. York University- CSE 3401- V. Movahedi 08_IO 10...
View Full Document

Page1 / 5

IO 2 - York University- CSE 3401- V. Movahedi 08_IO 8...

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