[ Obsolete | Reference Manual | Alphabetic Index ]
readvar(+Stream, -Term, -VarList)
Succeeds if the next Prolog term from the input stream Stream is
successfully read and unified with Term, and any variables in Term are
collected in the list VarList, together with their names.
- Stream handle or alias (atom)
- Prolog term.
- A Variable.
This built-in predicate is obsolete!
This predicate has been superseeded by read_term/3 with the
Used to read the next term from the input stream Stream, unify it with
Term and store any variables in Term to the list VarList. This is a
list of pairs in the format [VarName|Var].
VarName is the literal input variable name expressed as an atom; Var is
the variable. The first element of the pair Varname is the atom
corresponding to the variable name, and the second element Var is the
If there is more than one Prolog term in the file, the term must be in
Prolog term format i.e. terminated by a period and a blank space
character, neither of which are retained by Prolog.
Modes and Determinism
- readvar(+, -, -) is semidet
This predicate is sensitive to its module context (tool predicate, see @/2).
Fails if a syntax error was detected and no term could be read
- (4) instantiation fault
- Stream is not instantiated.
- (5) type error
- Stream is not an atom or a stream handle, Varlist is not a variable.
- (190) end of file reached
- End of file was encountered before reading any character.
- (192) illegal stream mode
- Stream is not an input stream.
- (193) illegal stream specification
- Stream is an illegal stream specification.
- (198) reading past the file end
- Trying to read even after the error 190 was raised.
Term = atom
VarList = 
T = _50
L = [['X'|_50]]
?- system('cat file1').
?- open(file1,update,r), readvar(r,T1,V1),
T1 = f(_120, _122)
V1 = [['X'|_120], ['Y'|_122]]
T2 = g(1, _146) % the clauses are separate,
V2 = [['X'|_146]] % so the X's are different.
?- readvar(input, X + 2,V).
X + 1.
readvar(S,a(b,c),V). (Error 4).
readvar("string",a(b,c),V,). (Error 5).
readvar(output,X + 2,V). (Error 192).
readvar(atom,X + 2,V). (Error 193).
read_term / 3