Live data from Hacker News

Why Learn Prolog in 2021?

dstrohmaier.com

161–170 of 171 posts

Re: Why Learn Prolog in 2021?

#161

Earlier quoted context omitted.

>> Many predicates are non-terminating or extremely inefficient when faced with goal inversion, but are often 'fixed' by simply reversing the order of some of its rules (but making it useless in the original direction in the process). This is disappointing when trying to maximize prolog's biggest potential: building true total relations that can project in any direction with a single definition. I don't think that's…

> I cannot easily think of an example where changing the order of clauses (not "goals") in a predicate definition prevents the program from "runnign backwards". It's bad enough to use "directions" for what are properly called "modes", but it's positively counterproductive to say that anything in Prolog runs "backwards". Prolog always runs top-to-bottom, left-to-right, and this is precisely why it's easy to write nont…

I think everyone knows what we mean about "running code backwards" and I was sticking to the OP's choice of language for simplicity. I don't disagree with your (nevertheless pedantic) observation, however. I agree we should be more precise in our terminology.

Anyway my bad, I guess you can think of many cases if you try a little. I apologise. I was not in my programming mind today.

Re: Why Learn Prolog in 2021?

#162
post #64
post #53

I used Datalog a good deal in grad school (CS). It was frustrating at first, but once I figured it out, I liked it a lot. If you've never tried a declarative programming language, you should give Datalog a try.

+1 to Datalog -- it is fantastic for static analysis in particular! There are a bunch of papers from Yannis Smaragdakis' group on this; I built my thesis work on top of their system Doop [1] which is a whole-program points-to analysis written completely in Datalog. In general it's very nice to be able to prototype queries/inference rules quickly and then tweak clause ordering, etc for performance later if needed. [1]…

You might like Flix then: first-class datalog constraints https://flix.dev/

Re: Why Learn Prolog in 2021?

#163
post #88

I'm not convinced there's great utility in smart contracts, but if there is, I think there's a huge utility in contracts being declarative and statically typed, to avoid many of the problems we've seen with existing contracts. In that case, a statically typed Prolog dialect would be a good starting point. The contract would be a set of declarative rules describing acceptable next states of the contract. To make the c…

Lira[0] and its readable paper[1] is a good example of abstracting smart contracts into a statically typed, domain-specific language that describes the contract precisely at a high level. It's not Turing complete, which works for a large class of contracts (for instance, see the American and Asian options examples in [1]). One concern with logic programming is cost of computation, on Ethereum every transaction has a…

> DAO hack) because the developers were not able to easily reason about the implicit behavior or concurrency model.

I believe the DAO bug was a reentrancy bug, not a concurrency bug. The code was not written to be reentrant because the developer didn't realize recursion could be triggered via implicit behavior. Many reentrancy bugs are concurrency bugs, but I really think that's not the case with the DAO bug. I saw one proposed fix (not sure if it's the one that got finally accepted) that used a reentrancy flag to prevent the problem and called the flag a "mutex", but it wasn't actually a mutex, adding to the confusion about the root cause.

I really don't think execution of a single contract transaction is concurrent, and due to (eventual) serializability of blockchain transactions, the blockchain acts as if concurrent execution within a contract across miners doesn't exist. If you have concurrent calls to a single contract, at most one of them will succeed, and those that fail will not affect the blockchain state.

In general, the Ethereum community seems to refer to serialized execution of contract methods in an order unexpected by the contract author as "concurrency", but I have seen no evidence that the effects on the contract state as reflected in the blockchain are not always serializable. In other words, it acts much like concurrent SQL queries under a serializable isolation level: if two concurrent executions modify the same data, one of them will fail instead of you getting an interleaving of the two write sequences.

It's possible that I misunderstand the EVM, but it seems insane to design a system to allow multiple threads to execute within a single contract at a time in the presence of shared mutable state, at least without an RDBMS-like isolation system in place.

Edit: https://forum.ethereum.org/discussion/1317/reentrant-contrac... supports my understanding.

Re: Why Learn Prolog in 2021?

#164
I've worked with Prolog and ASP (Answer Set Programming) in some planning/optimization projects. In my experience in every case ASP had better expressiveness.

If you are seriously considering logic programming, please do not stop with prolog, but also take a look at ASP.

For anyone with a different experience than mine - what is your reason to stick to prolog instead of use ASP?

Re: Why Learn Prolog in 2021?

#165
post #88

I'm not convinced there's great utility in smart contracts, but if there is, I think there's a huge utility in contracts being declarative and statically typed, to avoid many of the problems we've seen with existing contracts. In that case, a statically typed Prolog dialect would be a good starting point. The contract would be a set of declarative rules describing acceptable next states of the contract. To make the c…

You should check out the Digital Asset Modeling Language, DAML. [0] They've built a language for distributed ledger platforms based on Haskell with defined state transitions based loosely on traditional contract law. For exactly the reasons you've mentioned, this makes modeling the participants, rights, and obligations of a smart contract use case incredibly efficient. Whether smart contracts are useful or not remain…

I presume DAML is based loosely on SPJ's "Composing Contracts" paper. A few years ago at work, I was involved with a compiler from a DSL loosely based on SPJ's Composing Contracts. The compiler is a transpiler from contract descriptions to Cuda/OpenCL/ISPC code that runs a Monte Carlo simulation to calculate theoretical present value of the contract. The use case is complex derivative pricing and risk management.

Re: Why Learn Prolog in 2021?

#166

It might be easier to learn prolog, if non-essential costs were removed, by using a more familiar language as a wrapper[1], or for metaprogramming. Prolog's value lies in its database core. But much of the cost of learning a new language is elsewhere, in dealing with yet another different set of ways to do familiar things. With prolog, those differences are relatively uninteresting, so why not punt? Not having to dea…

That's my hunch too. Prolog is a different world and you still want to keep one foot in more mainstream languages. The idea should be use Prolog where it gives real advantages and use mainstream languages where it doesn't. So how do you divide your application into those two "islands"? Answer: Use persistent Datalog for database/persistence but do the rest in you bread-and-butter language. Basically saying replace SQ…

No recommendations, sorry, merely a couple of thoughts.

Prolog and datalog start out as rather different beasts, though prolog tabling gets them closer. It's an area of current research[1].

A datalog implementation can serve as DSL, learning tool, and/or efficient solver of large problems. For the first two, most languages have a little datalog implementation or three.

For datalog engines, perhaps Z3 and its fixpoint engine from python?? Or maybe Soufflé from python?? But I really have no idea what's plausible. I too would be interested.

> database/persistence

That's something with a big diverse active market. Datalog engines, not so much. So I'm unclear that datalog is a place to go for that? But I also pay no attention to non-open-source offerings.

[1] https://arxiv.org/pdf/1909.08246.pdf

Re: Why Learn Prolog in 2021?

#167

Every developer should learn Prolog or a logic language in their career. It's mind-bending in the best way, and opens your eyes to how a computer can do work for you by you describing the problem instead of the solution. SQL is a language that could have been a Prolog. In fact, querying in Prolog in general is absolutely beautiful. Prolog is homoiconic like lisp; extending the language with new features is trivial as…

at a higher level, don't all programming languages do some amount of work for you? like fundamentally all programming boils down to manipulating electrons in a circuit board or something, it's just different programming languages from assembly to SQL provide different ranges of abstraction for what they handle vs what the programmer had to handle

Re: Why Learn Prolog in 2021?

#168

Because you will likely be glad you did. Then go look at PicoLisp, which has Prolog baked into it. https://picolisp.com/wiki/?home

Is pilog just a mini logic programming language implementation or what you would call a full prolog engine?

Sorry, I'm not qualified to say. I cut short my dives into both Prolog and PicoLisp. Too many segfaults (myfaults) in PicoLisp. I need more hand-holding or time. I'm keeping my Prolog books though. Will return to them _someday_. Firmly of the opinion that if I could learn one prog-lang Matrix-style (plugged into my neck), it would be PicoLisp. Then I'd port it to run on the BEAM.

Re: Why Learn Prolog in 2021?

#169

Earlier quoted context omitted.

Is pilog just a mini logic programming language implementation or what you would call a full prolog engine?

Sorry, I'm not qualified to say. I cut short my dives into both Prolog and PicoLisp. Too many segfaults (myfaults) in PicoLisp. I need more hand-holding or time. I'm keeping my Prolog books though. Will return to them _someday_. Firmly of the opinion that if I could learn one prog-lang Matrix-style (plugged into my neck), it would be PicoLisp. Then I'd port it to run on the BEAM.

I also like the concept of picolisp, but ran into a lot of segfaults myself and eventually gave up. The learning material needs more handholding for sure. Also, I'll never be able to run that in production at my place of employment, so I could only use it for hobby projects.

Re: Why Learn Prolog in 2021?

#170
post #64

Earlier quoted context omitted.

+1 to Datalog -- it is fantastic for static analysis in particular! There are a bunch of papers from Yannis Smaragdakis' group on this; I built my thesis work on top of their system Doop [1] which is a whole-program points-to analysis written completely in Datalog. In general it's very nice to be able to prototype queries/inference rules quickly and then tweak clause ordering, etc for performance later if needed. [1]…

Probably worth mentioning for those interested in Datalog that there's actually a growing selection of databases for Clojure that use Datalog as their query language. These Clojure variants of Datalog (they model triples as Clojure data structures) are basically becoming as ubiquitous in Clojure as SQL is elsewhere. I have documented them here: https://github.com/simongray/clojure-graph-resources#datalog

TerminusDB, Crux and Grakn are other databases that use Datalog variants. Becoming a big thing.
Post reply on HN