TL;DR: Don't use get0/1
!
get0/1
is considered deprecated—even by Prolog processors that implement it (like SWI).
Instead, use get_char/1
and represent strings as lists of characters—not as lists of codes!
read_command(Chars) :-
get_char(Next),
read_command_aux(Chars, Next).
read_command_aux(Chars, Char) :-
member(Char, ['.', '\t', '\n', end_of_file]),
!,
Chars = [].
read_command_aux([Char|Chars], Char) :-
get_char(Next),
read_command_aux(Chars, Next).
Here are some sample queries using SWI-Prolog 7.3.15:
?- read_command(Chars).
|: abc
Chars = [a, b, c].
?- read_command(Chars).
|: abc.
Chars = [a, b, c].
?- read_command(Chars).
|: 123abc
Chars = ['1', '2', '3', a, b, c].
For further use of commands you might want to utilize atoms, like so:
?- read_command(Chars), atom_chars(Command, Chars).
|: abcd.
Chars = [a, b, c, d],
Command = abcd.
Note that this does not only work with SWI, but also with SICStus Prolog 4.3.2 (and others).