To work on #388 and other interesting projects, we need a way to read lists of characters from external files.
This is what library(pio) is for, and in particular its phrase_from_file/2. In its eventual form, phrase_from_file/2 will of course read a given file lazily, reading only what it needs, and reclaiming everything that is no longer needed.
However, even now, a very basic form of library(pio) and its phrase_from_file/2 would already be tremendously useful. A rudimentary implementation simply reads the entire file into a list of characters (of course using the compact UTF-8 based encoding), and then applies the given nonterminal to that list of characters.
Later, phrase_from_file/2 can simply be transparently replaced by the better version, reading the file lazily, interacting nicely with GC etc. All application code can remain exactly the same.
One important point: For the rudimentary version, no stream handling at all is needed on the Prolog side. Reading the entire file can be done in Rust, with the Prolog level only seeing a list of characters.
The implementation could look like this:
phrase_from_file(NT, File) :-
'$file_to_chars'(File, Chars),
phrase(NT, Chars).
This may be an interesting issue for Rust programmers.
It's brilliantly implemented in #396, so I'm closing this issue.
Many thanks @notoria!
I am late with my skepticism, and this is only for political reasons: The current version will sooner or later be criticized for being "inefficient" - well that's the rough wind in LP - even if it is better by a factor of 24 to start with. And as long as GC is not implemented, there is no better way...
Rough wind is good for sailing, we will reach new shores with this very nice feature.
Thanks to this innovative system and such great contributions, the current generation of researchers will be the first to see what Prolog actually is and can be. Let's focus on them.
Most helpful comment
It's brilliantly implemented in #396, so I'm closing this issue.
Many thanks @notoria!