Did you know ... Search Documentation:
Title for wiki('Annotation--annotation')
0 upvotes 0 0 downvotes
Picture of user LogicalCaptain.

This corresponds to "serialization/deserialization" in Java and other languages.

You CAN but shouldn't use this for reading input typed in by the user.

Example:

?-
with_output_to(
   string(Buf),
   write_term(a(b,c,[1,2,3],var(ZZ)),[])),  % serialize a term as string to "Buf"
read_term_from_atom(Buf, T, []).            % unserialize a term from Buf into T

Buf = "a(b,c,[1,2,3],var(_7256))",          % the serialized term
T = a(b, c, [1, 2, 3], var(_7848)).         % the usnerialized term; not the fresh unbound variable with the default name _7848

Use readutil for user querying:

library(readutil): Read utilities

Example:

format("Answer me!\n"),
read_line_to_string(user_input,S1),
string_lower(S1,S2),
(member(S2,["yes","1","ok","y","ja","oui"])
   -> format("OK!")
   ; (format("NOK"), fail)).
Answer me!
|: YES
OK!