PrologLanguage

ThoughtStorms Wiki

Context RelationalProgramming

The original "programming in logic" language

Implemented with WarrenAbstractMachine

What is the most interesting combination of programming language types (e.g. dynamic, static, weak, strong, functional, procedural, etc)?

Apr 15, 2019 https://www.quora.com//What-is-the-most-interesting-combination-of-programming-language-types-e-g-dynamic-static-weak-strong-functional-procedural-etc/answer/Phil-Jones-He-Him

For me, I think there's a whole fascinating world to be discovered if we go back and look at declarative logic / relational programming.

Prolog is still basically the last language of that paradigm that had much impact on most people's consciousness.

But just as functional programming is finally getting some traction and people are increasingly using languages from the Lisp and ML families, I think in the next 10 years we'll see a rediscovery of the declarative logic / relational paradigm. And just as Clojure (I believe) was a clever, tasteful and useful improvement / modernization of Lisp. So I think we'll see some equivalent clever, tasteful and useful modernizations of Prolog.

I'm not a huge fan of static types. But it would be interesting to see what a Prolog + decent type system (Hindley-Milner etc.) looked and felt like.

I'm quite interested to see what a Prolog in a "Smalltalk-like dynamic and live environment" looked like. Eve was moving in that direction. Maybe Dynamicland hints at fascinating "event-driven language in the physical world" too.

In fact, the secret, I believe of bringing Prolog into the modern world is to solve the problem of connecting it to real stuff. Real data. A real operating system. Etc.

Perhaps give it a bit of syntax to explicitly represent talking about / interacting with the world outside itself. I'd like to see something like "templates" as a first-class citizen of a Prolog-like language.

Eg. "unification" of a template data-type with slots it contains would fill the template. Which is then just declared to map on to something in the environment : whether that's a file, or the motors controlling a robot, or build-pipeline etc.

I'd love to see a Prolog-like with internal facts automatically mapped to things outside itself.

Quora Answer : Which programming language that most would consider a dead language today looks like it might be poised to make a comeback in the next 5-10 years?

Aug 20, 2019

Prolog.

I've been playing with SWI-Prolog in the last few months, and it is awesomely brilliant (at what it's good at)

Prolog, like other things, is probably taught wrong. It's taught as a historical curiosity. Or as a way of doing difficult logic puzzles which are often highly abstract and hard to get our heads around.

If Prolog was introduced with more but simpler logic puzzles that reflect ordinary programmer concerns I think people would be more interested.

I've recently been playing with slurping a crawl of my file-system into Prolog statements. So I can ask questions like "which directories have a .git subdirectory, and have a README, but don't have a git-remote at GitLab"

It's a fascinating overview of all the confusion on my machine. (And hopefully is helping me get it in order).

Of course, I'm doing the slurp by crawling the machine with Python and FSQuery because I haven't figured out how to do that properly in Prolog yet. (Though that would be the ideal).

What turns out to be surprisingly easy in SWI-Prolog though is to put a web-server on it, and so serve up standard queries of my file-system database, through web-pages. It's remarkably similar, both conceptually and in terms of complexity to how I'd do it in Python with Bottle or similar. In fact the built-in DCG based DSL for html is as good as I've seen in any other web framework. I have no doubt that someone could implement an equivalent of a DSL for a React-like UI with this too.

Prolog is selling itself to me as a way to do things I wouldn't dream of doing in other languages. What it lacks is obvious ways to do other common tasks.

What I think we're waiting for is for someone to do to Prolog what Rich Hickey and friends did to Lisp to make Clojure. Do a clean slate reinvention, ignoring "standards" but keeping the good ideas and tweaking it to work more straightforwardly with today's computing environment.

I think if someone were to do that, this new language would be very hot.

Quora Answer : Why doesn't Prolog have the same cult following as Lisp?

Nov 16

It probably does have passionate fans.

Deservedly so.

But Prolog is a little bit less "practical" than even Lisp.

I don't mean less less "powerful" or "useful"

It's massively powerful and useful.

But it's harder to slot into your normal practice and most contexts we program in today.

Even more than Lisp, Prolog is a language that makes many hard things easy, but some easy things hard.

At various times Lisp has found practical niches for scripting or other applications.

Prolog's niches are even more specialized and obscure.

So I suspect the community of people with Prolog knowledge is smaller to begin with. And the cult is smaller.

But I think the ideas of Prolog are incredibly powerful and relevant. In the last decade we've seen both Clojure (a new reinvention of Lisp) and Pharo (not quite a reinvention of Smalltalk, but with Glamorous Toolkit a quite radical and exciting new thing) both gain followers and reignite excitement in these traditions.

I'm waiting for someone to do the same with Prolog. SWI is remarkably good. (It's surprisingly easy to set up a web-server as UI to your application) But I suspect SWI is going to be to Prolog what Racket is to Lisp. A powerful but niche continuity product.

So I'm waiting for someone to do to Prolog what Clojure does with Lisp : break it sufficiently to fit into the contemporary world of software development, but keep 90% of the good stuff.

And it could be incredible.

Also :

Phil Jones (He / Him)'s answer to How would you design the perfect programming language?

Phil Jones (He / Him)'s answer to Why is logic programming overlooked? Can we use it for developing any kind of software?

Phil Jones (He / Him)'s answer to What is the programming language you are looking for and why?

Quora Answer : Will logic programming replace functional programming?

Dec 17

tl;dr : If it can be packaged in a convenient enough form.

My brief experiences with playing with SWI Prolog is that it's more interesting and powerful than I previously thought.

But it's not quite convenient enough to do the kinds of things I want to with.

As an experiment I wrote a Python program that crawled my file system, found all the interesting "projects" (git repositories, README files) and wrote information about them out in a big file of Prolog facts. I then wrote a Prolog program which ran a web server, slurped in these facts, that let me run various queries on them via a web interface. (Eg. typical query : find me all the git repos that have Python code, that don't have a README file)

The web-server part was surprisingly easy. Not much different from doing the same thing in Python's Flask or Bottle.

And I found this analysis of the mess on my hard-disk quite useful.

But obviously running a Python program to gather the data as a prerequisite every time I wanted to use the program was a bit of a faff. What I'd really like is a nice high-level declarative API to the file system and to data in files, and to the rest of the operating system. From within Prolog.

I had previously written a Python library (fsquery) to let me access the file-system the way jQuery talks to the DOM or Pandas talks to data-frames. And that made it pretty easy to write this crawling script.

It ought to be possible for Prolog to wrap the file-system in a similar declarative API so you could do this kind of query on the fly from inside Prolog. But I couldn't find anything like it or see how to do it myself.

In my mind, Prolog ought to be like LINQ etc., able to wrap any data or resource in a standard API for querying and slicing and dicing it declaratively. I mean, that seems to be the promise of this kind of programming.

But the higher-level abstraction building you'd need for that seems alien to Prolog.

This might be my ignorance and the fact that I didn't get enough into it. But I was struck by seeing many code examples that recursively ran through lists to do something with them. But no equivalent of the "map" and "fold" type functions which could abstract away from having to write your own recursive run through lists or other data structures.

The impression I got was that Prolog doesn't have the capacity to build these kinds of abstractions and APIs. In Prolog you are kind of stuck, with powerful built-in capabilities but no ability to construct yet higher levels of abstraction.

But if logic / declarative programming could be given that capacity, and we could build up these kinds of LINQ-like higher-level declarative APIs for data resources, whether files, file-systems, databases, activity streams etc. then a Prolog-like language could be excellent for writing scripts to analyse and munge big-data. Or, say, manage machine learning projects. It would be great to have the rules you need to extract data from a data-base and use it to train a neural network in a clean, convenient Prolog-like form. Able to automatically backtrack and try different strategies depending on how a particular training turned out.

But how could Prolog be hooked up to the necessary infrastructure / libraries?

This is why I'm betting on a breakthrough as someone invents a new logic / declarative language that goes beyond Prolog in some of these capacities. Particularly the ability to build new abstractions and provide common APIs to external data resources. That would start to make logic programming interesting to many more people.

Quora Answer : Why is logic programming overlooked? Can we use it for developing any kind of software?

Aug 14, 2018

"Logic programming" has the same kinds of problems as "functional programming".

But more so.

It's even less like what you're familiar with. And so "weirder" and harder for most people to get their head around.

It depends on even more back-end magic. Is even harder to reason about performance. And was perceived as slow back when computers were more limited.

I have an interesting story about this.

Everyone is thinking of Prolog, of course. But there's a language that's rather like Prolog, in the sense that a) it's a language tightly integrated with a knowledge base, and effectively just operates on that; and b) allows you to write your operations / transformations and inferences declaratively. You don't have to worry about how it's done. It just what you want done.

And while it isn't necessarily efficient, specialists could tweak the engine for efficiency while ordinary programmers could happily ignore performance.

And unlike Prolog, this language had spectacular, world dominating success for three decades. It was the standard that everyone knew and used. And it was plenty efficient enough.

That language is, of course, SQL.

And then suddenly there was a backlash against it. A NoSQL movement. That effectively wanted to go back to 1960s style hierarchical databases.

Some of that backlash was from large companies that really did have so much data that it was too big for the standard RDBMSs. But a lot of people for whom a relational database would serve just fine, jumped on the bandwagon.

Why?

Well, I suspect you should never underestimate the dark pull on programmers of the idea of "taking back control" over the low-level. For many programmers (myself included, some days) doing things the dumb old-fashioned imperative way just requires less thinking. Even if we dress it up in concerns about performance.

The second reason, is that there was less of the ORM "impedance mismatch" if we made our databases look more like the data-structures we were using inside the language itself.

That's a lengthy diversion. But something to keep in mind when asking why no logic programming - say, a logic programming "sub-language" with an impedance mismatch to everything else you're doing - is taking off.

Then there's a useful point made here: Logic programming is overrated.

That the inference engine in logic languages mainly runs through a bunch of possibilities filtering them out for you.

Depending on exactly which possibilities, any decent high-level language today, has a pretty elegant and short way of writing "filter this lazy collection" code.

Now, before everyone jumps on me, I'm not saying that that argument is universal, or kills logic programming. But I'm willing to bet that there is a significant chunk of applications of the form "search this tree of possibilities" where, if in 1972 you'd compared writing them in C to writing them in Prolog, Prolog would have come across as magic: it would be so concise and powerful compared to the hellishness of C. But, comparing the same Prolog code to running a couple of nested comprehensions in Python or Haskell or equivalent filters in Ruby or Clojure and the difference is far less.

Right, and now for that thing which is either "the elephant in the room". Or the thing that is going to reveal me as the ignoramus I probably am.

Negation.

Every time I sit down and try to do something in Minikanren or Prolog I end up crashing into some variant of a negation problem. Usually something like "show me all the pairs of potential students who are free at the same time and interested in the same course but who aren't the same person" (To be honest, I think it WAS a miniKanren I hit this in most recently, not Prolog.)

This really should not be something that's hard or requires counter-intuitive thinking. It's pretty straightforward in SQL if I remember correctly.

But as a novice Logic Programmer,is every time I hit a negation-related question, I'm thrown way deeper into having to understand the execution model than I should have to be. Reasoning about negation in most cases easy for people. Logic languages should be just as easy.

Now ... all this sounds like I'm hostile to logic programming.

I'm not, I'm really excited about declarative / logic languages at the moment: see Phil Jones (He / Him)'s answer to What programming language that has appeared recently in the last 10 years are you currently interested in or want to learn?

There's a lot I want to learn about these languages. I commented on Alexander Tchitchigin's comment just now that I'd love to see the Prolog community take a couple of hints from Eve for defining UIs.

In fact, I'm pretty open about being an unabashed Clojure fanboi. Clojure is the nicest language I've ever seen and used.

I'd love to see someone do to Prolog what Rich Hickey and friends did to Common Lisp. Which is say "here's a great idea, but let's just do a clean-slate reinvention, strip out all the historical cruft and stuff that doesn't make sense to us, add a couple of tasteful good ideas from elsewhere and a focus on modern platforms / applications" In Prolog's case that might be to look at and borrow ideas from Eve, from Erlang, from Datalog and Bloom etc. Even from SQL. I'm not sure. Maybe some syntactic sugar, and tweaks to the inference engine. You might be able to come up with some slightly higher-level abstractions over using the raw cut.

I can imagine a fantastic language coming from someone taking the Rich Hickey approach to Prolog.

Bookmarked at 2021-06-17T20:47:05.465 https://apice.unibo.it/xwiki/bin/view/Tuprolog/

Bookmarked at 2021-06-17T20:47:03.222 http://www.jiprolog.com/

Bookmarked at 2021-06-17T20:46:58.780 https://gitlab.forge.hefr.ch/tony.licata/prolog-truffle

Quora Answer : Why doesn't Prolog have macros like Lisp even though both languages are homoiconic?

Dec 2

Prolog is not a "functional" language.

It dispenses with the idea of functions and control over calling them, in favour of using "relations" which don't have explicit calling control but can be tested at various times, afford backtracking and search etc.

A "macro" is basically just a particular type of function which runs at compile time and operates on code.

Given that Prolog has no functions and doesn't give the programmer control over when things are run, how would "a function that is called at compile time" make sense in that world?

Quora Answer : Do you think Prolog Language is still relevant today?

Dec 20, 2018

I think the ideas of Prolog are very relevant. And that logic / declarative rule-based programming is going to make a come-back in the next 10 years, the way that functional programming finally broke through into mainstream consciousness and use over the last 10.

I'm not entirely convinced that it will be in the form of Prolog. It might be that someone does for Prolog what Clojure does for Lisp : make a new more convenient derivative of it. Or it might be more like Eve. Or through a hybrid language that sneaks a rule-base into a more traditional language, much like Javascript and even Python sneaked functional ideas into the mainstream.

But it's absolutely worth learning Prolog to get an idea of the paradigm, and looking out for wherever the paradigm starts reappearing.

See also :