Prolog supports pure I/O with library(pio). To read from a file, we write a DCG, and then use phrase_from_file/2 to apply the DCG to the contents of a file. library(pio) can be implemented very efficiently and is already available for several Prolog systems, including SICStus Prolog and Scryer Prolog.