By thinking in LP terms, like FP, LP requires rewiring the brain to think differently how to approach algorithms.
Here is a sample on how to read a file.
https://lpn.swi-prolog.org/lpnpage.php?pagetype=html&pageid=...
How to make syscalls,
https://www.swi-prolog.org/pldoc/man?section=foreign