From f59e957d741814459a0dca2993a4d3d4a2325688 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 22 Mar 2014 01:02:47 +1100 Subject: Reorganising code --- read.prolog | 56 -------------------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 read.prolog (limited to 'read.prolog') diff --git a/read.prolog b/read.prolog deleted file mode 100644 index 63d3ae7..0000000 --- a/read.prolog +++ /dev/null @@ -1,56 +0,0 @@ - -:- module(read, [prompt/1, readList/1]). - - -% functions for obtaining a line of input text and parsing -% it into a list of words - -% prompt provides the user with a '>' prompt as well -% readList merely obtains and parses the input - - -prompt(L) :- - write('> '), - readList(L). - - -readList(L) :- - readLine(X), - wordList(L,X,[]), !. - - -readLine(L) :- - get_char(C), - readLine_tail(C,L). - - -readLine_tail('\n',[]) :- !. -readLine_tail(C,[C|X]) :- - get_char(C2), - readLine_tail(C2,X). - - -wordList(X) --> whitespace, wordList(X). -wordList([X]) --> word(X). -wordList([X]) --> word(X), whitespace. -wordList([X|Y]) --> word(X), whitespace, wordList(Y). - - -word(W) --> charList(X), {atom_chars(W,X)}. - - -charList([X|Xs]) --> char(X), charList(Xs). -charList([X]) --> char(X). - - -whitespace --> whsp, whitespace. -whitespace --> whsp. - - -whsp --> oneOf(_,[' ', '\r', '\n', '\t']). -char(X) --> noneOf(X,[' ', '\r', '\n', '\t']). - - -oneOf(X,L) --> [X], {member(X,L)}. -noneOf(X,L) --> [X], {not(member(X,L))}. - -- cgit