Live data from Hacker News

The Simplicity of Prolog

bitsandtheorems.com

11–20 of 134 posts

Re: The Simplicity of Prolog

#11
How can I use Prolog to actually get something done, other than academic tasks?

Say I want to use it as a database query language, presumably that's not going to happen, right?

Re: The Simplicity of Prolog

#12
> The reverse predicate from this section should not be used in practice - most Prolog implementations actually provide a built-in version which is a lot more performant than our implementation.

That feels like cheating. If you shouldn't use the implementation shown, then why do you even show it? Let us see the performant version!

That's like Haskell's quickSort implementation in a couple of lines... beautiful but horrendously non-performant as it doesn't actually implement the algorithm, it just implements the "idea" (while losing all the performance of the actual algorithm, which requires in-place mutation).

Re: The Simplicity of Prolog

#15
post #11

How can I use Prolog to actually get something done, other than academic tasks? Say I want to use it as a database query language, presumably that's not going to happen, right?

In a sense, Prolog _is_ a database query language. The base facts in Prolog are equivalent to the rows of a table. You can also ‘table’ predicates with variables (over a finite subset of values) by memoizing the results.

Re: The Simplicity of Prolog

#16
I started learning prolog just a few months ago, when I stumbled upon https://linusakesson.net/dialog/ which is a spin on prolog optimized for writing interactive fiction.

As a sweet and short tutorial I can recommend these slides: https://www.cs.toronto.edu/~hojjat/384w10/

If you want to dive into how Prolog works under the hood I can recommend https://github.com/a-yiorgos/wambook

I terms of Prolog implementations I played a bit with https://www.scryer.pl but it still feels rough around the edges.

SWI-Prolog is the most popular and most batteries included Prolog: https://www.swi-prolog.org With its libraries and documentation it is a very practical language. What surprised me is, that you can easily produce amazingly small stand-alone binaries.

Re: The Simplicity of Prolog

#17

> While SQL isn't normally used as a general purpose programming language I think it's quite illustrative for those otherwise unfamiliar with declarative languages (though apparently it is Turing complete) SQL itself is not Turing complete in its standard form because it lacks some essential features of a Turing machine, such as the ability to simulate unbounded loops or recursion within a single query. SQL with proc…

Ansi SQL 99 defines recursive ctes.

https://en.m.wikipedia.org/wiki/SQL:1999

Re: The Simplicity of Prolog

#18
post #12

> The reverse predicate from this section should not be used in practice - most Prolog implementations actually provide a built-in version which is a lot more performant than our implementation. That feels like cheating. If you shouldn't use the implementation shown, then why do you even show it? Let us see the performant version! That's like Haskell's quickSort implementation in a couple of lines... beautiful but ho…

No built-in is needed for an efficient reverse. It's just one or two lines longer because you need to write a tail-recursive helper with an accumulator, same as in functional languages: https://stackoverflow.com/a/74777180

Re: The Simplicity of Prolog

#19
post #11

How can I use Prolog to actually get something done, other than academic tasks? Say I want to use it as a database query language, presumably that's not going to happen, right?

> Datalog is a declarative logic programming language. While it is syntactically a subset of Prolog, Datalog generally uses a bottom-up rather than top-down evaluation model. This difference yields significantly different behavior and properties from Prolog. It is often used as a query language for deductive databases.

https://en.m.wikipedia.org/wiki/Datalog

Re: The Simplicity of Prolog

#20

I have a long standing love affair with Prolog and frustration for its failure to grow. Prolog has poor features for abstraction and is actually not declarative enough! Prolog's limitations can be great for starting to get the paradigm but then you hit a wall. (Kind of like standard Pascal!) Mercury and Curry fix some of these limitations as does miniKanren. Integrating CLP is important yet so far always clumsy as st…

> Prolog has poor features for abstraction

That's actually what this article presents as its strength and simplicity. The straightforward choice in Prolog is to use global "who may do what" tables. In contrast, the author overengineers a Kotlin solution and then says "look, this is overengineered". I think global tables would make the Kotlin code half as long and much simpler too.

> Mercury and Curry fix some of these limitations

At the cost of introducing new ones. Mercury makes it effectively impossible to pass around partially instantiated structures.

Post reply on HN