Live data from Hacker News

The Power of Prolog

metalevel.at

131–140 of 164 posts

Re: The Power of Prolog

#131

Earlier quoted context omitted.

Why couldn't you just tell them you were going to have to rewrite it if you couldnt get it embedded?

It wasn't already written in prolog. It just would've been much easier and more straightforward for that particular application to write the business logic side in prolog. From a UI standpoint, I've never used prolog for a GUI so it would've needed to be embedded in something else (likely C# given the office preference) anyways, so the decision was to put everything in C# and skip my prolog idea. If I still had those…

> they do what's needed to make it easy to hire maintainers by sticking to popular languages and frameworks instead)

And completely miss the moment where the new maintainer comes in and says:

"!@#$ why didn't they just write this in prolog? freaking PHB's"

Re: The Power of Prolog

#132

Earlier quoted context omitted.

This is all true, but only for the small subset of Prolog that happens to be introduced on that web page. This analogy breaks down as soon as you have more complex data, not just atoms, or as soon as you introduce recursive rules. Prolog tutorials really do Prolog a disservice by introducing it as a database query language, which is then misunderstood (or misremembered) by many as "it's only a database query language…

SQL can do recursive rules too. SQL tutorials often do SQL a disservice by introducing it as a database query language rather than relational algebra :) example=# select * from move; place | method | newplace ---------+--------+---------- home | taxi | halifax halifax | train | gatwick gatwick | plane | rome (3 rows) example=# create view on_route as with recursive on_route(place, newplace, length, path) as (select p…

Ha, excellent :-) I learned something, thanks.

(The greater point still stands, terms and unification and all that.)

Re: The Power of Prolog

#133

Earlier quoted context omitted.

Sure and thanks for the wait! To give a bit of background: I run a service for some folks that allows them to get status messages. Some of my users wanted stats on the kinds of messages they received. My first implementation was quick and dirty: shell scripts which would run filters and aggregations through combinations of grep, sort, and uniq. Eventually as more demands came in with different types of functionality,…

Just to clarify, it was O(n^2) for n the length of the string, not the number of statuses. Right?

Correct.

Re: The Power of Prolog

#134

Prolog's mathematical foundation is sound but the devil is in the details, and very soon, you encounter two of Prolog's most glaring flaws that lead to spaghetti code worse than what even BASIC ever produced: - It's dynamically typed - The cut operator

If you like Prolog, but want static typing and no cut operator, you might really like Mercury (https://mercurylang.org/).

Re: The Power of Prolog

#135

i have always trouble understaing prolog, lot of guide online seem to just tackle the syntax or assume you already know a lot of logic programming, for example the first example in the link ( https://www.metalevel.at/prolog/facets ): list_length([], 0). list_length([_|Ls], N) :- N #> 0, N #= N0 + 1, list_length(Ls, N0). i don't undestand it, i read the segment describing it multiple time but i still don't get it, and…

Same here, I don't think this is a particularly great way of starting with Prolog. I have found these videos helpful for understanding Prolog:

https://www.youtube.com/watch?v=SykxWpFwMGs

https://www.youtube.com/watch?v=G_eYTctGZw8

Re: The Power of Prolog

#136
post #28

i have always trouble understaing prolog, lot of guide online seem to just tackle the syntax or assume you already know a lot of logic programming, for example the first example in the link ( https://www.metalevel.at/prolog/facets ): list_length([], 0). list_length([_|Ls], N) :- N #> 0, N #= N0 + 1, list_length(Ls, N0). i don't undestand it, i read the segment describing it multiple time but i still don't get it, and…

The fact list_length([], 0) says "the length of an empty list [] is 0". The clause says "the length of the list [_|Ls] (i.e, any element concat Ls) has length N if N>0, N=N0+1, and the length of Ls is N0". Hope this helps.

Why do you have to specify that N>0?

Seems to me that this ought to be sufficient:

the list [_|Ls] has length N if N=N0+1, and the length of Ls is N0

Re: The Power of Prolog

#137
post #23

i have always trouble understaing prolog, lot of guide online seem to just tackle the syntax or assume you already know a lot of logic programming, for example the first example in the link ( https://www.metalevel.at/prolog/facets ): list_length([], 0). list_length([_|Ls], N) :- N #> 0, N #= N0 + 1, list_length(Ls, N0). i don't undestand it, i read the segment describing it multiple time but i still don't get it, and…

Check out https://en.wikipedia.org/wiki/Horn_clause You can read this as two statements: "The length of a list is 0, if the list is empty." "Otherwise, if the length of a list Ls is N0, and N is N0 + 1, and N is greater than 0, then Ls with an additional element is of length N.

Excellent. How am I supposed to interpret this, or being able to write code? Even Erlang is much more readable and understandable at the first sight. :)

Re: The Power of Prolog

#138

I bookmarked this. I have been revisiting my own programming history. I used Prolog a lot in the 1980s, partially because I was influenced by the ill-fated Japanese 5th generation project. A few weeks ago I pulled my old Prolog code experiments from an old repo. Prolog is a great language for some applications, and Swi-Prolog has some great libraries and sample programs. I also have used Common Lisp a lot since the 1…

You had version control systems in the 80s? I had cassette tapes and later 5 1/4 inch floppy disks!

Re: The Power of Prolog

#139
post #116
post #83

Earlier quoted context omitted.

Prolog was part of course that I'd taken during my Masters. I loved it then. I would love to take a closer look when I have time ... whenever that happens ... Interestingly, IBM Watson uses Prolog. [1] [1] https://www.cs.nmsu.edu/ALP/2011/03/natural-language-process...

IBM uses a special version of Prolog with a different syntax and database access functionality. They hired a department of a university. MS Windows (network code) contains a Prolog with C-style-syntax.

> MS Windows (network code) contains a Prolog with C-style-syntax.

Can you tell me details?

Re: The Power of Prolog

#140
post #83

Earlier quoted context omitted.

Not really. I use SWI Prolog for a lot of personal projects (that actually see QPS no less) and there's a lot more to it than that. SWI gives you: good debugging support (with trace and spy), hooks into the Prolog database (with asserta/z and retract), optimized implementations of difference lists, online help, and so much more. Don't even get me started on its amazing DCG support that makes Regex feel like a Neolith…

Prolog was part of course that I'd taken during my Masters. I loved it then. I would love to take a closer look when I have time ... whenever that happens ... Interestingly, IBM Watson uses Prolog. [1] [1] https://www.cs.nmsu.edu/ALP/2011/03/natural-language-process...

I used it for a graduate course in formal semantics. As our final project, we had to implement Lisp in Prolog and prove the semantics formally. Until that point, I thought I had a good grip on Prolog. Debugging the project nearly drove me nuts! If I had a do-over, I'd learn the SWI debugging tools before attempting it.

I love Prolog and hope to spend more time with it some day. But, the step from Novice to Intermediate is steep.

Post reply on HN