]> Repositorios git - scryer-prolog.git/commitdiff
use more recently available phrase_[to|from]_file/3 in example
authorMarkus Triska <[email protected]>
Sun, 23 Nov 2025 08:42:14 +0000 (09:42 +0100)
committerMarkus Triska <[email protected]>
Sun, 23 Nov 2025 08:42:14 +0000 (09:42 +0100)
src/examples/utf8.pl

index bee6b2b24f4d1c3851ab19332aebfd8226c8913e..d8112011c6071fcc0261ee8c61ea5d6273ff9e28 100644 (file)
@@ -1,5 +1,7 @@
 :- use_module(library(charsio)).
 :- use_module(library(lists)).
+:- use_module(library(pio)).
+:- use_module(library(dcgs)).
 
 :- initialization(unit_test).
 
@@ -10,22 +12,12 @@ unit_test :-
   Cs = "a£\x2124\".
 
 write_f :-
-  open('x.txt', write, Stream, [type(binary)]),
-  F = put_byte(Stream),
   chars_utf8bytes("£\x2124\\x2764\\x1F496\\n", Bs),
-  maplist(F, Bs),
-  close(Stream).
-
-get_bytes(Stream, Res) :- get_bytes(Stream, [], Res).
-get_bytes(Stream, Acc, Res) :-
-  get_byte(Stream, B),
-  (B =:= -1 ->
-    reverse(Acc, Res)
-  ; get_bytes(Stream, [B|Acc], Res)).
+  maplist(char_code, Cs, Bs),
+  phrase_to_file(Cs, "x.txt", [type(binary)]).
 
 read_f :-
-  open('x.txt', read, Stream, [type(binary)]),
-  get_bytes(Stream, Bs),
-  chars_utf8bytes(Cs, Bs),
-  write(Cs),
-  close(Stream).
+  phrase_from_file(seq(Cs), "x.txt", [type(binary)]),
+  maplist(char_code, Cs, Bs),
+  chars_utf8bytes(Chars, Bs),
+  write(Chars).