
Learn Prolog Now - febin
http://www.learnprolognow.org/lpnpage.php?pageid=online
======
ghufran_syed
Datalog is a form of prolog, used currently by a database called datomic as
it's query language. If you wanted to play with datalog, the best way is to do
the free tutorial at www.learndatalogtoday.org you don't need to anything
about datomic or clojure in order to do the tutorial, and I found it really
helpful to get an idea of how it would be really helpful for certain types of
queries, compared to an analogous query in SQL (which I also like btw...)

[Edit] - funny, someone _just_ posted this other tutorial to HN too, haven't
done it yet but looks fun and educational, it's a murder mystery!
[https://xmonader.github.io/prolog/2018/12/21/solving-
murder-...](https://xmonader.github.io/prolog/2018/12/21/solving-murder-
prolog.html)

~~~
slifin
All my upvotes, it's criminal how under hyped Datomic is

Hyperfiddle is a paradigm shift on the front end too, using the same concepts,
imagine real time GraphQL on steroids where the query doesn't need a horrible
SQL translation on the backend and that doesn't even begin to cover it, no
worrying about multiple round trips, SQL injection gone, cache invalidation
solved, supports recursion, nested data

Everyone outside of Clojure/Datomic should be looking in for things to steal

~~~
brudgers
Datomic's popularity is constrained by the decision to make it closed source
commercial software. That's not a knock. It's not saying Datomic is not worth
the money. Profitability in exchange for popularity is a very reasonable
decision.

The decision not to play around with the free version of proprietary software
is also reasonable. Vendor lock-in is a trade off many developers are not
interested in making.

~~~
bgorman
There now an open source alternative to Datomic suitable for small
applications:
[https://github.com/replikativ/datahike](https://github.com/replikativ/datahike)

------
xvilka
There is also more modern Power of Prolog[1][2]. Another interesting language
is ProbLog[3] - Probabilistic Prolog, seems used in bioinformatics.

[1] [https://www.metalevel.at/prolog](https://www.metalevel.at/prolog)

[2] [https://github.com/triska/the-power-of-
prolog](https://github.com/triska/the-power-of-prolog)

[3]
[https://dtai.cs.kuleuven.be/problog/](https://dtai.cs.kuleuven.be/problog/)

~~~
mathnmusic
Also, there is MiniZinc:
[https://www.minizinc.org/](https://www.minizinc.org/)

------
dang
A discussion from 2015:
[https://news.ycombinator.com/item?id=9246897](https://news.ycombinator.com/item?id=9246897)

And one from 2010:
[https://news.ycombinator.com/item?id=1976127](https://news.ycombinator.com/item?id=1976127)

------
yardie
Wow. I wish this existed when I was in middles school, trying to write science
fair project in prolog. It sent me down an academic rabbit hole that was way
above my depth of knowledge. And the books I could find were really dry
academic oriented. But I powered through and wrote a prolog program to help
identify poisons.

------
mrccc
A friend of mine wrote a Chrome extension for better styling:
[https://chrome.google.com/webstore/detail/learn-prolog-
now-e...](https://chrome.google.com/webstore/detail/learn-prolog-now-
enhanced/gojfoljalmhohccaganmbgbffmfffhcg)

------
qwerty456127
Why? No, really, subjectively Prolog looks lovely to me, but sort of "Chapter
0" explaining why should people learn Prolog and how they can apply it
practically could make an awesome addition.

~~~
brudgers
As an abstraction, think of a Prolog program as a collection of facts and
running a Prolog program as a query against those facts. Or basically a Prolog
program as a static (or read oriented) database. Or describing a set of rules.

Rolling back, as a declarative language in the database abstraction, the
programmer can run queries with _verbs_ that model the domain instead of SQL's
generic WHERE, FROM, SELECT, etc. The price is that all facts have only three
parts...like RDF [1] so maybe the programmer comes out ahead on design of the
data relations.

Not all workloads are close to read-only databases. But some are, and Prolog
allows writing such programs without the low level abstractions of the
relational model using higher level DSL's.

[1]:
[https://en.wikipedia.org/wiki/Resource_Description_Framework](https://en.wikipedia.org/wiki/Resource_Description_Framework)

~~~
qwerty456127
How does storing facts in the source code instead of a database make any
practical sense? I mean I can hardly imagine a real-life scenario where the
number of facts is so small.

~~~
ben-schaaf
Facts are both data and "source code". It's a fact that a user with id=0 has
name=Bob. It's also a fact that the sqrt(x^2)=x or the http response code when
a resource isn't found is 404. Some of those belong in databases, some
definitely don't.

------
pkteison
The thing that intrigued me the most about Prolog was that true and false are
not opposites. True means it could prove it, but false means it couldn’t prove
it in time, not strictly necessarily really false as in not true. Thinking
about that distinction, that you can have a language where the default logic
can’t be used for Boolean algebra, blew my mind when I was in college and has
been fun to ponder ever since.

~~~
taneq
Sounds more like true and null? Or does it not definitively disprove things?

~~~
tom_mellior
The parent is mistaken. A "false" answer definitely means that no (further)
solution exists. You can ask for time or depth limits in practical Prologs,
but in basic standard Prolog "false" doesn _not_ mean "could not prove it in
time".

Of course some things cannot be disproven, and in those cases (again, if you
don't request otherwise) you will get nontermination.

------
raphinou
I dived into prolog this year, and I really liked it. However, I didn't find a
very active community to answer questions. The lack of energy in the
community, and my wondering where I could use prolog for a practical
application, tempered my enthousiasm, and I switched to learning something
else (category theory).

~~~
tu7001
What sources do you have to learn category theory?

~~~
raphinou
I watched Bartosz Milewski's videos
[https://m.youtube.com/playlist?list=PLbgaMIhjbmEnaH_LTkxLI7F...](https://m.youtube.com/playlist?list=PLbgaMIhjbmEnaH_LTkxLI7FMa2HsnawM_)

The pdf generated from his blog is also interesting :

[https://github.com/hmemcpy/milewski-ctfp-
pdf](https://github.com/hmemcpy/milewski-ctfp-pdf)

These are the best resources I found about the subject.

~~~
tu7001
Videos are awesome, I started watching them and ended up binge watching!

------
jonahx
For those wanting to kill the "learn logic programming" and "learn a golfing
language" birds with one stone, check out:

[https://github.com/JCumin/Brachylog](https://github.com/JCumin/Brachylog)

------
eismcc
SWI-Prolog to WebAssembly:

[https://github.com/JanWielemaker/swi-prolog-
wasm/blob/master...](https://github.com/JanWielemaker/swi-prolog-
wasm/blob/master/README.md)

------
xte
Nice!

I've study a super-little-bit prolog at university time but I do not really
understand it... I still have to understand "why prolog?" at all but perhaps
sooner or later I'll try to review it a bit with this site-book :-)

~~~
arthurcolle
Prolog is great for a thing called constraint satisfaction. You define a bunch
of predicates, which may or may not have meaning in the implicit dependencies,
and then the language is able to extract logical relationships between those
atoms in these defined predicates. You might have had an instructor who
himself hadn't really mastered the language, or maybe he didn't grok it -
because it's very beautiful and intuitive when its laid out properly. It was
the language I picked up the fastest in all of my coursework, just super
elegant and bare bones.

OT, but another point to note is that the original Erlang VM and interpreter
was implemented in Prolog, which (because of Joe Armstrong's affinity for the
language) might be why there are so many subtle syntactical similarities
between the two languages.

This tutorial does a pretty good job at first glance, but I feel like there
could be some more sophisticated examples that more concretely illustrate why
it's such a powerful technique to use

~~~
xte
Well I (not really) "learn" for a side course just to get some extra credits
(I do not know if this mechanism exists outside western EU) so... I can
practically say that I only have seen it's syntax and play with it at a so
ignorant level that I do not really understand it's motivations...

Constraint satisfaction to my eyes seems a bit of an obscure concept that is
substantially present in any functional programming language, however since
prolog is still there and popup regularly I understand that it's me that miss
something and so I'm curious and perhaps sooner or later I'll try to reread
docs and try to really understand while keep it a bit down in my priority
list...

------
njn
I was going through this recently because my brother is going through the CS
program that I went through, which is the only time I've encountered anyone
mention Prolog. I still can't really envision how to create comprehensive
systems in this, but it seems the logic paradigm could be applied to some
really useful new areas that it hasn't reached yet, similar to how the
influence of functional languages is pretty much expected for any trendy new
language today (Rust, ES6).

~~~
Koshkin
I think it helps to think of Prolog as something similar to SQL. See, for
example, [https://stackoverflow.com/questions/2117651/comparing-sql-
an...](https://stackoverflow.com/questions/2117651/comparing-sql-and-prolog).

~~~
tom_mellior
It doesn't really help to think that way. The accepted answer to that
StackOverflow question sounds very much like the poster didn't really know
what Prolog is (and possibly confused it with Datalog).

Here is code to append two lists in Prolog:

    
    
        append([], Xs, Xs).
        append([X|Xs], Ys, [X|Zs]) :-
            append(Xs, Ys, Zs).
    

You can use this as follows ("?-" is the user input prompt, equations are the
system's answers):

    
    
        ?- append([a,b], [c,d], Zs).
        Zs = [a, b, c, d].
    
    
        ?- append(Xs, Ys, [a,b,c]).
        Xs = [],Ys = [a, b, c] ;
        Xs = [a],Ys = [b, c];
        Xs = [a, b],Ys = [c];
        Xs = [a, b, c],Ys = [].
    

How would you express the notion of lists in SQL? How would you express the
notion of appending two lists? And how would you express the notion of
searching for all possible pairs of lists that, when appended, yield the list
[a,b,c]?

------
User23
I quite enjoy watching successive generations of programmers rediscover prolog
in particular and rule-based programming in general. It's well worth learning
even if you never really use it, because it expands your understanding of the
art.

------
justbaker
I tried swipl prolog and enjoyed it but poor PostgreSQL support scared me
away. Any prolog developers have any advice? I really like prolog but need an
implementation with good db support for specifically Postgres but haven’t
found anything.

~~~
YeGoblynQueenne
You don't need SQL if you have Prolog. Prolog itself can store and retrieve
all your data, except that data is also your program at the same time.

For instance, see:

 _Can I replace a LAMP stack with SWI-Prolog?_

[http://www.swi-prolog.org/FAQ/PrologLAMP.html](http://www.swi-
prolog.org/FAQ/PrologLAMP.html)

~~~
justbaker
This is a really great answer, thank you.

~~~
YeGoblynQueenne
Cheers. Note also that you can relatively easily move all your SQL tables to
Prolog by exporting them as text files with Prolog facts of the form:

    
    
      <table_name>(<column 1, row 1>, <column 2, row 1>, ...., <column n, row 1> )
      ...
      <table_name>(<column 1, row m>, <column 2, row m>, ...., <column n, row m> )
    

So each table becomes a predicate with the table name as its predicate symbol
("functor" in Prolog), the number of the columns in the table as its arity
(the number of arguments of the predicate) and where each row of the table is
a separate clause of the predicate.

Many tables exported this way will not be necessary any more, particularly
those ubiquitous tables used to map other tables' keys between them
("Customer_ID_Ticket_Id" etc) and in most cases primary key fields will no
longer be necessary and so on- but you can move all your data to Prolog, with
very little change, is what I'm trying to say.

Mer' Christmas :)

~~~
justbaker
Nice! That gives me faith for using it for my personal projects. I enjoyed
erlang when I programmed in it in my fledgling days and I like the tenseness
of the prolog-influenced languages. Having a very easy way to port to a
platform(or off, sometimes) is certainly a valid concern of mine when choosing
my tooling. Merry Christmas to you as well :)

------
tjpnz
Prolog is a language I have fond memories of but haven't touched in a long
time. How applicable is it outside of academia given all of the alternatives?

------
momofarm
So for the end of year 2018, is there still people using Prolog in profession
field instead of academic?

------
me2too
This is the website I used to learn Prolog and all I can do is to highly
recommend it

