4 ms·
You want pure I/O in an untyped language. DCGs are the easiest way to have that (although they also have their limits).
by rscho 4y ago
You want pure I/O in an untyped language. DCGs are the easiest way to have that (although they also have their limits).
- nerdponx 4y agoWhat do you mean by "pure I/O" in this case? And how does logic programming help with that? I've seen things like this in the context of "algebraic effects", where instead of performing I/O (and instead of using monadic I/O) you build up what amounts to an execution graph of effectful operations, which is then "interpreted" at runtime. Is that what you're describing?
- rscho 4y agoNo, what I'm describing is the "monadic" behaviour of `phrase_from_file/2` and similar predicates. In conjunction with definite clause grammars, this means that your I/O operations either conform to the provided spec or fail. This is a "hot topic" (if LP topics can really still be "hot") and sees active development in new prolog systems. Check this out for prolog: https://youtu.be/Dqpxy4W7fAo https://youtu.be/Dqpxy4W7fAo https://www.swi-prolog.org/pldoc/man?section=pio https://www.swi-prolog.org/pldoc/man?section=pio https://github.com/mthom/scryer-prolog/blob/084fc845902f7b435b0e5e44aaeba023bc28958f/src/lib/pio.pl https://github.com/mthom/scryer-prolog/blob/084fc845902f7b43... "New" stuff in the MiniKanren world: https://staff.fnwi.uva.nl/c.u.grelck/nl-fp-talks/kourzanov.pdf https://staff.fnwi.uva.nl/c.u.grelck/nl-fp-talks/kourzanov.p... https://ifl2014.github.io/submissions/ifl2014_submission_18.pdf https://ifl2014.github.io/submissions/ifl2014_submission_18....
- YeGoblynQueenne 4y ago(Not the OP) Thanks for the links, because 14 years after I first started coding in Prolog I'm still not sure what Pure I/O is or why it is. I mean, my intuition is that a file is a stream of bytes and wading through that stream is not going to be "pure" no matter what, just because a byte is not a concept in First Order Logic. But, OK, "pure" Prolog is not the same as FOL anyway, and so I may be convinced otherwise when I have the chance to peruse your links. So thanks again and sorry for any negative vibes emanating from my comment.
- rscho 4y ago"pure" prolog I/O is every bit as pure as Haskell pure I/O, which is ... not very much and in a hand-wavy sort of way. My understanding is that it basically means "either it corresponds to the spec, or it fails". At first, it seems trivial and a strange point of pride to have. Until you realize that most languages actually don't have anything built-in to do that, and must resort to some sort of parser. At which point, the data is already past your I/O gateway and may lead to unpredictable effects in your program. This is not an academic opinion, just my 2c.
- YeGoblynQueenne 4y agoThanks for taking the time to reply! I appreciate your 2c. I guess my confusion about pure I/O stems from the documentation of phrase_from_file/2 in SWI-Prolog. The documentation says the predicate is for pure I/O and how it was implemented, and by whom, but it doesn't say what pure I/O is, and why it is needed. I guess the information is somewhere in one (or more) of the canonical Prolog textbooks, which I've only read several years ago (though multiple times over, each). I have to confess also I'm not much of a purist. My Prolog code looks like bog standard imperative code where I feel it doesn't really matter (e.g. I don't have any prejudice about setof/3 or maplist/2 over findall/3), and I guess file I/O is one of those cases. Anyway, thanks again, for your links and explanation. I owe you a quantum of knowledge :)