I was in a class recently that had a session on logic programming, emphasizing Prolog. I was aware of Clojure having core.logic and so I looked into that one with its mini-kanren implementation. While I appreciate that there are major fields – NLP, AI – that make use of logic programming, it is equally striking how strange a methodology it is compared to conventional programming (e.g. goals, predicates, relations instead of functions, strange binding procedures, etc). Our toy project was to look at family relations (with facts like “father” and “mother,” then defining relations based on those facts like “sibling” and “cousin”) and throughout the effort I could only think how much easier this would be using regular maps and value checks.
Has anyone here worked productively in logic programming? What sorts of tasks does it facilitate more effectively than standard Clojure/functional programming?
Datomic’s Datalog implementation is a good first contact and can be explored here: http://www.learndatalogtoday.org/ In that sense, anyone using Datomic or really any relational database is already thinking in similar ways.
To me, functional programming is about respecting equality in one direction and logic programming about respecting equality in both directions. It seems very natural to express a domain mostly through its relations without picking a “direction”. You only ever state what is true about your domain. Constraint solvers and linear programming are very similar in that regard and immensely useful (e.g. in layouting algorithms). And after all, this is also how equations work in mathematics.
Timoth Baldridge recently gave a talk about building a logic engine and he mentioned that he has built several of them for various projects, most recently at his current job at Cisco.
IIRC, he mentioned using them to efficiently do complex searches in both financial systems as queries across big datasets to identify possible malware.
What I always wondered about core.logic is: how do you estimate the complexity of the task? like, on a database, I check for indexes, define plan hints… so I know a query will take milliseconds and not hours for a full table scan. But with core.logic?
Recommend the video talks linked in their pages for explaining the value props of using a logic engine. Even Mr Hickey himself recommended logic programming /prolog over raw Clojure for implementing business rules in many scenarios in “Simple Made Easy”
My company uses “Rules” in Datomic to express business logic. It really helps us declare relationships and access rules without writing tons of hard to maintain conditional code paths