3 ms·
> "I think Prolog really shines as an embedded query engine[...] It's perfect for declarative configuration, very easy to write powerful queries once you wrap y
by jodrellblank 3y ago
> "I think Prolog really shines as an embedded query engine[...] It's perfect for declarative configuration, very easy to write powerful queries once you wrap your head around it."
Can you explain more, or give any examples?
VoidTools' Everything gives me a fast search over all files on my disk, it's some carefully optimised low level code, and I can search with wildcards or regex. Even if it supported it, I wouldn't want to change `cat*.jpg` to `findall(file(F), (file(F), name(F, FName), substring(FName, _, _, _, "cat"), append(_, ".jpg", FName)), Files)`.
That's horrible so it's probably not at all what you're thinking of; on the other hand I'm endlessly pleased with `?- apropos(string).` in SWI Prolog. What kind of things are you thinking of where it could/does shine?
- grose 3y agoI think a compelling use case is flexibly defining rules. Biscuit’s Datalog tutorial does a good job of illustrating how you can go from simple auth to RBAC with just a few lines of code. https://www.clever-cloud.com/blog/engineering/2021/04/15/biscuit-tutorial/ https://www.clever-cloud.com/blog/engineering/2021/04/15/bis... For your particular example, using DCGs like: file(X), phrase(("cat", ..., ".jpg"), X). Is a bit clearer. You can use DCGs to do all kinds of parsing and generating (and in this case, testing). But they aren’t going to be as fast as a highly optimized regex engine.