summaryrefslogtreecommitdiff
path: root/stdlib.pl
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib.pl')
-rw-r--r--stdlib.pl56
1 files changed, 52 insertions, 4 deletions
diff --git a/stdlib.pl b/stdlib.pl
index d31e3ab..0986781 100644
--- a/stdlib.pl
+++ b/stdlib.pl
@@ -217,10 +217,6 @@ write_canonical(Term) :-
write_canonical(S, Term) :-
write_term(S, Term, [quoted(true), ignore_ops(true)]).
-nl :-
- write_term('
-', []).
-
% Arithmetic comparisons defined in terms of >=. This is not the most effective way,
% but it is fine for now.
@@ -501,3 +497,55 @@ atom_concat(A1, A2, A3) :-
atom_codes(A2, Codes2).
atom_concat(A1, A2, A3) :-
instantiation_error.
+
+% Character input/output
+
+get_char(Char) :-
+ current_input(S),
+ get_char(S, Char).
+
+get_code(Code) :-
+ current_input(S),
+ get_code(S, Code).
+
+get_code(S, Code) :-
+ get_char(S, Char),
+ ( Char = end_of_file
+ -> Code = -1
+ ; char_code(Char, Code)
+ ).
+
+peek_char(Char) :-
+ current_input(S),
+ peek_char(S, Char).
+
+peek_code(Code) :-
+ current_input(S),
+ peek_code(S, Code).
+
+peek_code(S, Code) :-
+ peek_char(S, Char),
+ ( Char = end_of_file
+ -> Code = -1
+ ; char_code(Char, Code)
+ ).
+
+put_char(Char) :-
+ current_output(S),
+ put_char(S, Char).
+
+put_code(Code) :-
+ current_output(S),
+ put_code(S, Code).
+
+put_code(S, Code) :-
+ char_code(Char, Code),
+ put_char(S, Char).
+
+nl :-
+ current_output(S),
+ nl(S).
+
+nl(S) :-
+ put_char(S, '
+'). % This should really be \n