commit 8fd3f5a4a89579774026f0f661c2e2ec6303537a
parent 521fa8d01f615a4424866e0a12d3711098c9ef7d
Author: St John Karp <contact@stjo.hn>
Date: Tue, 25 Aug 2020 17:29:10 -0500
Fix some GNU-Prolog bugs in the helpers
Fixed a bug in the join predicate where I left out one of the
parameters. Also rewrote the read_file predicate so it looks for
-1 instead of testing at_end_of_stream. -1 seems like a more reliable
indicator when reading from a command's output.
Diffstat:
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/helpers.pl b/helpers.pl
@@ -5,12 +5,13 @@
% read_file(+Stream, -Codes).
% Read a file to a list of character codes.
-read_file(Stream, []):-
- at_end_of_stream(Stream).
-
-read_file(Stream, [Code|Rest]):-
- \+ at_end_of_stream(Stream),
+read_file(Stream, Codes):-
get_code(Stream, Code),
+ read_file_next(Code, Stream, Codes).
+
+read_file_next(-1, _, []).
+
+read_file_next(Code, Stream, [Code|Rest]):-
read_file(Stream, Rest).
@@ -50,7 +51,7 @@ join([], _, '').
join([A], _, A).
join([First|Rest], Separator, Result):-
- join(Rest, End),
+ join(Rest, Separator, End),
atom_concat(First, Separator, FirstPlusSeparator),
atom_concat(FirstPlusSeparator, End, Result).