5 ms·
As I see it, the most striking feature of Prolog that sets it apart from all other languages, mainstream or not, is its ability to write concise meta-interprete
by triska 5y ago
As I see it, the most striking feature of Prolog that sets it apart from all other languages, mainstream or not, is its ability to write concise meta-interpreters in it.
A Prolog meta-interpreter is a Prolog program that interprets Prolog programs. With this facility, you can dynamically extend your programs, by reading code and executing it as if it were part of the original program. But not only that, you can also reason about it, and execute it in different ways than a regular Prolog engine would do it. You can analyze it, and execute only safe parts. You can remove fragments, and show explanations why specific phenomena occur. You can debug it declaratively by constructing generalizations and specializations. You can add features to the language that are not present in its actual implementation, but only in the programs you interpret.
No other programming language provides this ability to such an extreme extent as Prolog. For example, how much C++ code would it take to write an interpreter for a sensible subset of C++? How much Lisp code would it take to interpret the most essential aspects of Lisp? It takes only 3 lines of Prolog code to interpret the essence of Prolog.
Most programmers may currently not "miss" this ability, because what they think of when they think of a "program" is in comparison quite static: The idea that they could interpret external code dynamically as part of their programs is alien to them because the languages they are using either does not allow it, or only allows it in a sense "blindly", by not truly looking into the code and interpreting it in flexible ways, or by making the analysis of given code too hard. Yet, the ability to conveniently adapt and augment the logic of an existing program is a fundamental necessity for truly general and flexible programs that must dynamically take into account changing requirements.
- heavenlyblue 5y agoNone of what you just said seems to have any substance as it all sounds very abstract and easily doable in other languages (I.e. Python through exec). What should I read in order to understand the difference?
- eismcc 5y agohere’s some info from the author: https://www.metalevel.at/acomip/ https://www.metalevel.at/acomip/
- coliveira 5y agoThe parent's point is very clear, but I guess you never had the opportunity to see it in action. Basically, you can write a Prolog interpreter for the full language very easily (a few lines), and this interpreter can extend the original language in any way you want. So you can not only write your own DLS, but do any kind of reasoning/transformation/interpretation/debugging with the new constructs, almost for free, no knowledge of compilers is needed. This is how people write new languages based on Prolog.
- kazinator 5y ago> How much Lisp code would it take to interpret the most essential aspects of Lisp? Just: (eval code).
- harperlee 5y agoI think he refers to how much code does eval need, which might be about 15-20 lines.
- deleted 5y ago[deleted]
- remexre 5y agoThough it gets much longer to implement all of the special forms present in CL, some of which are going to be tougher than others (e.g. TAGBODY).
- harperlee 5y agoSure but Common Lisp is a huge spec, I think the comparison ought to be against scheme.
- deleted 5y ago[deleted]