Live data from Hacker News

Why Learn Prolog in 2021?

dstrohmaier.com

111–120 of 171 posts

Re: Why Learn Prolog in 2021?

#111
post #89
post #79

Earlier quoted context omitted.

If you're interested in learning many paradigms, the Oz[0] language, Mozart system, and accompanying textbook[1] were designed as a teaching tool to teach most of the major paradigms in a single language. I have not sat down with them, but they have been on a far back burner for years. [0] https://en.wikipedia.org/wiki/Oz_%28programming_language%29 [1] https://en.wikipedia.org/wiki/Concepts,_Techniques,_and_Mode...

Definitely! It's been on my backburner for years as well. I have the book and started to take the edX course a couple of years ago, but got sidetracked with work. I e-mailed Peter Van Roy back in May, asking if the edX course would be resumed. He stated that the local university course got removed from the engineering curriculum, so that's why the edX course isn't running anymore. Hopefully it comes back. He mentione…

Super glad to see this!

Programming Paradigms for Dummies (https://info.ucl.ac.be/~pvr/VanRoyChapter.pdf) is something I try to get everyone I know who's interested to read and really think hard about.

The textbook is the only real textbook I've bought after university because it's so... foundational.

I like to refer to programming paradigms as the building blocks of design patterns -- how do you derive design patterns and best practices? By trying to bring programming paradigms into your design! Our practice of immutability can be viewed as a means to make data flow more deterministically.

Re: Why Learn Prolog in 2021?

#112
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…

Interesting point. The biggest counter-argument I see is the need for fine-grained optimization of gas usage. Especially given the crazy high fees as of late. Hand-tuned imperative C enjoys a performance advantage over functional and declarative alternatives. So I’d imagine that imperative smart contracts are inherently easier to optimize than Prolog-style contracts.

The thing is that declarative contracts separate execution from verification. You don't actually execute the contract in the miner/verifier. The client executes the contract and records a trace of the subset of the program necessary to verify execution. The miner/verifier just uses the trace to verify that the presented state is correct (top-level contract rule evaluates to true).

In the simple and common cases, there ends up being no difference between execution and verification. However, if you have a contract that has

  let F = (A() || B() || C() || D()) && ! E();
  let R = F() && (G() || H());
  R();
with an imperative contract that gets executed on the verifier, you need to optimally order the clauses A-D, taking into account the cost of each and the percentage of the transactions in which each one is true. The client isn't allowed to re-order the clauses in the contract. With a declarative contract that is executed client-side, the client tells the verifier exactly which one of the terms A-D needs to be evaluated and which of the terms G-H needs to be evaluated. Let's say G and D are the lowest cost functions that need to be evaluated to verify our transaction. If the execution trace is the child index taken in depth-first traversal of the tree of logical disjunctions in the contract expression then the trace indicating that D and G need to be evaluated is [3, 0]. This can be compactly represented as a single (potentially large) integer in a mixed-base number system. (In our case, the bases are 4 and then 2, so the single integer representing the trace is 2*0 + 3 = 3. The verifier first hits a 4-way disjunction, and 3 mod 4 is 3, so it only evaluates the 4th branch. 3 div 4 is 0. It next hits a 2-way disjunction and 0 mod 2 is 0, so it only evaluates the 1st branch.) If you order the logical disjunctions in your contract so that in the common case, the leftmost alternative is always taken, then in the common case, your execution trace as a mixed base integer is 0. With estimates of the probabilities of the branches, you could use an asymmetric mixed base number system, similar to Facebook's zstd compression to optimally represent your verification traces.

With a declarative contract, the cost of suboptimal ordering is borne by the client and not by the verifier.

With EVM, there's no separation of contract execution and verification. The verifier/miner needs to execute the contract at the request of the client. If you modify the EVM and contracts to keep track of what's provably side-effect free and allow the client to specify reordering of those terms, then you've by definition created a non-imperative language or sublanguage. In that case, it's much safer and easier to design the system from the ground up to have semantics that are invariant under evaluation order (that is, declarative semantics).

Most of the cost of declarative program optimization vs. imperative program optimization (deciding an optimal order) is borne on the client side. Due to the structure of the contracts and the traces, it's trivial to prove that portions of the contract don't need to be executed in order to verify the transaction.

Re: Why Learn Prolog in 2021?

#113

Earlier quoted context omitted.

My rough criteria: - does the language have some name recognition and positive reputation? - is it still in use (even if only in very niche areas)? - do you have a chance to use it to solve a problem (for work or for fun) to which the language is well suited? If the answer to all three is yes then I would have no hesitation.

To this, I personally would add as an "or" clause, "Does the language have something fundamental to teach me about programming that I don't already know, and which could be useful when brought to other domains?" This was the reason I learned FP, and also the reason I learned Prolog. I wanted to extend my understanding of programming beyond the C/procedural context. To that end, I found both exercises immensely benefi…

That's a fair point. I think that is worth highlighting. But I wouldn't make it an "or" clause.

For context, I've been able to satisfy all the criteria when learning both Prolog and Erlang. They were both profoundly education experiences, but I think part of the impact of that experience came from using them to solve problems I had, and to which those languages were well suited.

There are many languages that will teach me important concepts, but time to devote to learning them is limited. I need a filtering/prioritization process. The trick is to just be aware that these other languages exist, what domains they are good for, and be ready to learn them when I have the right problem.

Re: Why Learn Prolog in 2021?

#114
This brings up memories from 7 years ago. While in Uni, we had a homework: "Searching in an infinite space using Prolog".

Unfortunately, the comments are in my native language, but the assignment was to search for a box in an infinite space and bring it back to (0, 0).

It was fun: https://github.com/mateioprea/Searching-In-An-Infinite-Space...

Re: Why Learn Prolog in 2021?

#115

This brings up memories from 7 years ago. While in Uni, we had a homework: "Searching in an infinite space using Prolog". Unfortunately, the comments are in my native language, but the assignment was to search for a box in an infinite space and bring it back to (0, 0). It was fun: https://github.com/mateioprea/Searching-In-An-Infinite-Space...

[deleted]

Re: Why Learn Prolog in 2021?

#116
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…

> One concern with logic programming is cost of computation,

Right, but the client executes the contract, keeping a trace of what needs to be computed by the verifier. The verifier doesn't actually execute the full contract, just verifies that the trace was faithfully executed. If we have

  let R = (A() || B() || C() || D()) && ! E();
  R().
If A is costly, but true 99% of the time, but this transaction is one of the 0.001% of the cases where D() is true, the contract verification trace says to execute D(), and the verifier never checks A, B, or C. See my nearby comment for a worked out example of a compact trace representation for a deeper disjunction decision tree.

Effectively, because declarative languages don't dictate order, the client is free to re-order the contract execution order to be optimal for this particular execution, without altering semantics. Declarative semantics, are by definition, independent of execution order. This makes efficient compilation and execution more difficult, but makes verification faster (if the verifier is provided with an execution trace).

Now, you could potentially do similar optimizations with Solidity contracts, with a suitably modified EVM definition, but if the execution order is up to the runtime/compiler instead of dictated by the source code, then you've by definition changed the language to be declarative.

Re: Why Learn Prolog in 2021?

#117
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]…

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

Re: Why Learn Prolog in 2021?

#118
I still do not understand why they do not make Prolog that can do infinite. The calculation should be lazy parallel instead of serial. I think this might solve confusing problems that arise with bigger Prolog programs.

For example WRITE-statements can be lazy parallel too -- They would only start producing text when the answer is definite. Does not happen in any particular sequence anymore, but you must account that and use appropriate headings.

Re: Why Learn Prolog in 2021?

#119
post #16

This inspired me. What's the best book for modern prolog?

I liked "The Art of Prolog" for learning. And then if you dive deeper, "The Craft of Prolog". I'm curiously amused that the price for used versions on Amazon is so high. https://mitpress.mit.edu/books/art-prolog-second-edition https://isbn.nu/0262192500 https://mitpress.mit.edu/books/craft-prolog https://isbn.nu/9780262512275

I did some further research and it seems like The Art of Prolog gets the most love even though it's from the mid-nineties - and still hella expensive like you say!

The only thing I'm wondering about are skipping any important developments made in the last 25 years, but I guess I can always jump into the more up-to-date online resources by then.

Re: Why Learn Prolog in 2021?

#120
post #14

How do you guys think about the opportunity cost of learning dead/dying/new/unpopular languages? Even with newer languages that are gaining popularity and are likely to be used in the future, I struggle to justify the time investment. I could be wrong but some of my concerns are: - my time is better spent getting deeper into some more popular language that I already know to some extent - unused skills deteriorate wit…

If you care only about job prospects and your career, then I would skip it. However, if you like exploring different ideas and concepts in computer science, it is definitely worth a look.
Post reply on HN