]> Repositorios git - scryer-prolog.git/commitdiff
generalize read_from_chars/2 and read_term_from_chars/3 to allow instantiated Term
authorMarkus Triska <[email protected]>
Wed, 9 Apr 2025 20:23:12 +0000 (22:23 +0200)
committerMarkus Triska <[email protected]>
Thu, 10 Apr 2025 06:18:23 +0000 (08:18 +0200)
This addresses part of #2871, raised by @haijinSk. Many thanks!

src/lib/charsio.pl

index 2204d80daffeaf6960e0eb9ccca4171657247558..536aeac69489d4b976df346ef4e7b1272e5178ed 100644 (file)
@@ -195,7 +195,7 @@ get_single_char(C) :-
     ;  type_error(in_character, C, get_single_char/1)
     ).
 
-%% read_from_chars(+Chars, -Term).
+%% read_from_chars(+Chars, ?Term).
 %
 % Given a string made of chars which contains a representation of
 % a Prolog term, Term is the Prolog term represented. Example:
@@ -206,10 +206,10 @@ get_single_char(C) :-
 % ```
 read_from_chars(Chars, Term) :-
     must_be(chars, Chars),
-    must_be(var, Term),
-    '$read_from_chars'(Chars, Term).
+    '$read_from_chars'(Chars, Term0),
+    Term = Term0.
 
-%% read_term_from_chars(+Chars, -Term, +Options).
+%% read_term_from_chars(+Chars, ?Term, +Options).
 %
 % Like `read_from_chars`, except the reader is configured according to
 % `Options` which are those of `read_term`.
@@ -220,9 +220,9 @@ read_from_chars(Chars, Term) :-
 % ```
 read_term_from_chars(Chars, Term, Options) :-
     must_be(chars, Chars),
-    must_be(var, Term),
     builtins:parse_read_term_options(Options, [Singletons, VariableNames, Variables], read_term_from_chars/3),
-    '$read_term_from_chars'(Chars, Term, Singletons, Variables, VariableNames).
+    '$read_term_from_chars'(Chars, Term0, Singletons, Variables, VariableNames),
+    Term = Term0.
 
 %% write_term_to_chars(+Term, +Options, -Chars).
 %