Lately Prolog became my no. 1 language for stuff and I’ll blindly upvote anything Prolog related.
However for those interested in Prolog I’d recommend SWI-Prolog first.
Its standard distribution has everything and w kitchen sink included and I also found it the most stable. Performance is great unless code us stupid (e.g. yesterday I tried to reduce chain to MVP by naively iterating 1000 letters - it took couple second to get to completion as you can imagine).
I learned a bit of Prolog a long time ago (as part of a philosophy course at university!) and it sounds interesting but I have no idea of how useful it is.
- Data queries (e.g. given data X show me as much as you can across multiple systems)
- Cross API integration (e.g. show me a PRs that merged, but not marked as done in Jira)
- Data transformation (JSON -> XML -> YAML), e.g. Excalidraw to Graphviz to draw.io
- State transition checks (systems modeling)
- Diagram generation
- Code/Document generation
One of the most crazy ideas I have is one to generate C++ code for Cardputter in order to have a little Uiua machine. Arduino tooling is so slow (or it might be the thing for this specific board, no idea), that I figured it's going to be easier to develop it in Prolog and then generate C code from it (i.e. key handlers, rendering etc.)
Thing with Prolog is, that people think it's slow, but it's not. I agree that in 80's it might have not be usable, but today I'm having 2.1M Lips (Logical Iteration Per Seconds), so solution might not be inefficient but I save on the lines of code in the end.
That's super interesting. Do you use DCGs to read your data or do you call external libraries? How do you generate C code? Do you use a template system?
I rarely use DCGs because they suffer from completeness syndrome, i.e. you either define full DCG or you crash on first error.
For such tasks I prefer quasi-quotation [0] or a simple format with goal expansion [1]. As for readers I rarely need ones, because XML, YAML, JSON are already included.
In order to do code analysis I first pulled pieces using Regex (mostly headers) and only then parsed them over with DCG. Which is also neat when creating own DSLs - one can ask people on meeting to decorate lightly notes and get - semantic linking almost for free.
I hear you. Logic based and relational languages, like Prolog and miniKanren, have captured my attention a lot lately. One reason: I wondered if they might complement LLMs nicely, or if LLMs might be a good tool for helping people learn/understand logic languages.
While exploring the logic language space, I recently reacquainted myself with a branch of logic based languages based on *Clear/OBJ* that were born in the ‘70s at the University of Edinburgh. It never took off like Prolog, mostly because it was a research language focused on specification and verification, but a lot of the ideas have lived on in many modern languages. (Haskell, OCaml, C++, etc…)
First, imagine you wanted to create a Prolog inspired language that allowed a person to create their own domain specific languages like they were abstract data types. You can also create abstract data types. The goal of this language isn’t to create a lexer/parser tool, but rather a more integrated tool that is capable of specifying both abstract data types and DSLs with a formalized logic. Oh yeah, let’s make it modular, so you can mix and match specifications.
Clear/OBJ did just that, but they did it in a way built on a foundation of formal semantics. What I mean that is, Rod Burstall and Joseph Goguen used Category Theory to create an abstract formal specification that answers the question, “What is a logic?”
With this framework in place, Goguen formalized order sorted equational logic and used it as the basis for the OBJ language in the ‘70s and ‘80s. Jose Meseguer formalized rewriting logic (for rewrite based systems) and used it as the basis for his language Maude. Most recently, Grigore Rosu lead the creation of Matching Logic (Used by the K Framework) for specifying the semantics of full programming languages, as well as automatically generating the lexer, parsers. This system of logic lets them define the operation semantics and prove the properties using Hoare logic in a single language.
This one reference language semantics can derive program behavior (compilers/tooling) and verify programs.
This works because we have a framework for defining a system of logic like Matching logic, which isn’t based on True/False and predicate logic, but pattern matching and power sets.
Instead of defining Top/Bottom as True/False, what if Top/Bottom corresponded to pattern matching primitives like MatchesEverything/MatchesNothing?
My point is this: While I am loving this resurgent interest in Prolog, I feel like it’s easy to overlook the wider world of logic programming beyond Prolog & Datalog.
We have 50 years of incredibly insightful research that we can use to build the next generation of tools and systems to serve us.
8 comments
[ 2.3 ms ] story [ 36.0 ms ] threadHowever for those interested in Prolog I’d recommend SWI-Prolog first.
Its standard distribution has everything and w kitchen sink included and I also found it the most stable. Performance is great unless code us stupid (e.g. yesterday I tried to reduce chain to MVP by naively iterating 1000 letters - it took couple second to get to completion as you can imagine).
Prolog is fun, check it out :)
I learned a bit of Prolog a long time ago (as part of a philosophy course at university!) and it sounds interesting but I have no idea of how useful it is.
- Data queries (e.g. given data X show me as much as you can across multiple systems)
- Cross API integration (e.g. show me a PRs that merged, but not marked as done in Jira)
- Data transformation (JSON -> XML -> YAML), e.g. Excalidraw to Graphviz to draw.io - State transition checks (systems modeling)
- Diagram generation
- Code/Document generation
One of the most crazy ideas I have is one to generate C++ code for Cardputter in order to have a little Uiua machine. Arduino tooling is so slow (or it might be the thing for this specific board, no idea), that I figured it's going to be easier to develop it in Prolog and then generate C code from it (i.e. key handlers, rendering etc.)
Thing with Prolog is, that people think it's slow, but it's not. I agree that in 80's it might have not be usable, but today I'm having 2.1M Lips (Logical Iteration Per Seconds), so solution might not be inefficient but I save on the lines of code in the end.
For such tasks I prefer quasi-quotation [0] or a simple format with goal expansion [1]. As for readers I rarely need ones, because XML, YAML, JSON are already included.
In order to do code analysis I first pulled pieces using Regex (mostly headers) and only then parsed them over with DCG. Which is also neat when creating own DSLs - one can ask people on meeting to decorate lightly notes and get - semantic linking almost for free.
[0]: https://www.swi-prolog.org/pldoc/man?section=quasiquotations [1]: https://www.swi-prolog.org/pldoc/man?section=format-predicat...
While exploring the logic language space, I recently reacquainted myself with a branch of logic based languages based on *Clear/OBJ* that were born in the ‘70s at the University of Edinburgh. It never took off like Prolog, mostly because it was a research language focused on specification and verification, but a lot of the ideas have lived on in many modern languages. (Haskell, OCaml, C++, etc…)
First, imagine you wanted to create a Prolog inspired language that allowed a person to create their own domain specific languages like they were abstract data types. You can also create abstract data types. The goal of this language isn’t to create a lexer/parser tool, but rather a more integrated tool that is capable of specifying both abstract data types and DSLs with a formalized logic. Oh yeah, let’s make it modular, so you can mix and match specifications.
Clear/OBJ did just that, but they did it in a way built on a foundation of formal semantics. What I mean that is, Rod Burstall and Joseph Goguen used Category Theory to create an abstract formal specification that answers the question, “What is a logic?”
https://en.wikipedia.org/wiki/Institution_(computer_science)
With this framework in place, Goguen formalized order sorted equational logic and used it as the basis for the OBJ language in the ‘70s and ‘80s. Jose Meseguer formalized rewriting logic (for rewrite based systems) and used it as the basis for his language Maude. Most recently, Grigore Rosu lead the creation of Matching Logic (Used by the K Framework) for specifying the semantics of full programming languages, as well as automatically generating the lexer, parsers. This system of logic lets them define the operation semantics and prove the properties using Hoare logic in a single language.
This one reference language semantics can derive program behavior (compilers/tooling) and verify programs.
This works because we have a framework for defining a system of logic like Matching logic, which isn’t based on True/False and predicate logic, but pattern matching and power sets.
Instead of defining Top/Bottom as True/False, what if Top/Bottom corresponded to pattern matching primitives like MatchesEverything/MatchesNothing?
My point is this: While I am loving this resurgent interest in Prolog, I feel like it’s easy to overlook the wider world of logic programming beyond Prolog & Datalog.
We have 50 years of incredibly insightful research that we can use to build the next generation of tools and systems to serve us.