Can i convert from a list of chars to a string or term in Prolog
Question
i use
read_line_to_codes(Stream,Line)
to read a line from a file .. first is there any way to read a line and assign it to a term in prolog ?? if not i managed to read a line and put it in this char list .. now this char list contains spaces .. which is bad .. so i want to convert it to a term or a string in prolog so that i can process it easier .. spaces cannot be atoms so thats a problem ..
i appreciate the help !!
Solution
If your input consists of Prolog terms, use read/1. You can convert character codes to an atom with atom_codes/2. A space, ' ', is also an atom, you can see that with the query: ?- atom(' '). A good way to read other input from a file with SWI-Prolog is to describe it with a DCG and then to use phrase_from_file/2 from library(pio).