/* Practical example - 28th February 1984 - Helen Pain */ /* AI1 */ /* Consult the file 'ecmi04.printexs' */ /* this file contains some examples of input and output using read and write */ /* type go to start */ go:- write('remember to terminate your input with a full stop'),nl, nl,nl, process_atom, nl, process_atom, nl, process_atom, nl,nl, process_list, nl,nl, process_string, nl,nl, process_clause, nl,nl. process_string:- write('Type in a string, use double quotes'),nl, read(X), nl, write(X), nl,nl, write('strings are really lists of ASCII characters'),nl,nl, nl, prstring(X), nl,nl, write('but we can print them as characters using put'),nl,nl. process_clause:- write('type in a prolog rule'),nl, read(X), nl, write(X), nl,nl, write('read and write take terms - all clauses are terms'),nl,nl. process_list:- write('type in a list of items in square brackets'),nl, read(X), nl, prlist(X), nl,nl, write('we can print each item in the list using'), nl, write('a recursive call to prlist'),nl, nl, write(X), nl,nl, write('or we can just print the list using write'),nl,nl. process_atom:- write('type in an integer, a single word (not beginning with a'), nl, write('capital letter) or any characters enclosed in single quotes'), nl,nl, read(X), nl, write(X), nl,nl, nl. prlist([]). prlist([X|Y]):- write(X), nl, prlist(Y). prstring([]). prstring([X|Y]):- put(X), prstring(Y).