TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Rethinking Prolog

37 pointsby Zuiderover 2 years ago

7 comments

anentropicover 2 years ago
A better link: <a href="https:&#x2F;&#x2F;okmij.org&#x2F;ftp&#x2F;kakuritu&#x2F;rethinking.pdf" rel="nofollow">https:&#x2F;&#x2F;okmij.org&#x2F;ftp&#x2F;kakuritu&#x2F;rethinking.pdf</a><p>The OCaml library mentioned in the paper appears to be linked as individual files from the web page here: <a href="https:&#x2F;&#x2F;okmij.org&#x2F;ftp&#x2F;kakuritu&#x2F;Hansei.html" rel="nofollow">https:&#x2F;&#x2F;okmij.org&#x2F;ftp&#x2F;kakuritu&#x2F;Hansei.html</a><p>...not sure if it&#x27;s properly published as a package anywhere.<p>Looks like someone collected it to GitHub here: <a href="https:&#x2F;&#x2F;github.com&#x2F;cararemixed&#x2F;hansei">https:&#x2F;&#x2F;github.com&#x2F;cararemixed&#x2F;hansei</a><p>There&#x27;s some discussion here that the Hansei code may no longer work under OCaml 5: <a href="https:&#x2F;&#x2F;discuss.ocaml.org&#x2F;t&#x2F;multi-shot-continuations-gone-forever&#x2F;9072&#x2F;6" rel="nofollow">https:&#x2F;&#x2F;discuss.ocaml.org&#x2F;t&#x2F;multi-shot-continuations-gone-fo...</a><p>Could someone ELI5 for me how this stuff relates to Kanren? It looked superficially similar.
muizelaarover 2 years ago
Past thread: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=8305486" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=8305486</a>
YeGoblynQueenneover 2 years ago
Meh. As usual, functional programmers look at Prolog and completely miss the point. &quot;Classical Prolog&quot; (which part?) is &quot;all about nondeterminism&quot;?<p>The nondeterminism in Prolog comes from the completeness of SLD-Resolution as an inference rule. Because SLD-Resolution is complete [1], it can find every proof that exists. When there are many proofs, it is natural to have some mechanism to represent them all. Prolog does that by backtracking and trying different branches of a proof, hierarchically.<p>Parsing is indeed a good example of this. When a grammar is ambiguous, a string may have multiple different parses. But if a grammar is ambiguous, that&#x27;s because the language it represents is ambiguous, and that means we want to represent the ambiguity, and have multiple parses. That is where a mechanism for nondeterministic return of all results is needed. A parser written in Prolog [2] will naturally backtrack and get all parses of a string.<p>So how about that maudlin cut, that people, like the authors of the article above, have bitched and moaned about, since the creation of Prolog? Well the cut clearly exists to avoid reaching unwanted branches of a proof, or in other words, to avoid unwanted backtracking.<p>But why then is there unwanted backtracking? The reason for unwanted backtracking is, invariably, that a program is over-general. In over-generalising, the program non-deterministically generates results that the programmer did not want, even as it returns (hopefully first) the results that the programmer wants. But human programmers are not perfect, and sometimes it can be too hard to write a program that is exactly as general, and as specific, as one wants, especially when the program crosses some threshold of size beyond which it is difficult to keep all of one&#x27;s ducks in a row and understand exactly the behaviour of every single sub-program (i.e. predicate definition). That is when the cut is needed. The cut is a time-saver that keeps you from having to rewrite your entire program from scratch, multiple times, just because you are an imperfect programmer, and you cannot handle the full might of a programming language with Universal Turing Machine expressivity.<p>And more esoterically, perhaps, unwanted non-determinism arises because Resolution is semi-decidable, meaning that if a proof exists, Resultion will find it, but if a proof does not exist, it will keep trying forever. And that is the best that can be achieved under the Church-Turing thesis, and if you are unhappy with that, you can take your case with Mr. Gödel. In the meantime, you can use the cut to avoid your program going haywire, when you can tell (but the Prolog interpreter can&#x27;t, because Church-Turing) that a program will loop forever after succeeding n times.<p>The authors say that &quot;Classical Prolog&quot; (really, what is that?) is not a &quot;general purpose programming language&quot;. It is. Thanks to the cut. Now shoo, go code in your functional languages, which are safe and easy. Don&#x27;t mess with my Prolog because you don&#x27;t understand it.<p>___________________<p>[1] More precisely, SLD-Resolution is both sound and refutation complete.<p>[2] Generally, as a Definite Clause Grammar.<p>[3] <a href="https:&#x2F;&#x2F;www.doc.ic.ac.uk&#x2F;~rak&#x2F;papers&#x2F;IFIP%2074.pdf" rel="nofollow">https:&#x2F;&#x2F;www.doc.ic.ac.uk&#x2F;~rak&#x2F;papers&#x2F;IFIP%2074.pdf</a>
mikewarotover 2 years ago
I tried Turbo Prolog[1] back in the 1980s. I could never figure out how to get it to do file I&#x2F;O at that time, so I got frustrated and gave up. Even now, it looks fairly hopeless as a language.<p>Is there a modern example of the language that can do file I&#x2F;O? To me, if you can&#x27;t do I&#x2F;O, there&#x27;s no point to a language. It&#x27;s why Standard Pascal lost so much ground to Turbo Pascal with it&#x27;s excellent I&#x2F;O support.<p>[1] <a href="https:&#x2F;&#x2F;ia802902.us.archive.org&#x2F;1&#x2F;items&#x2F;bitsavers_borlandturOwnersHandbook1987_8438592&#x2F;Turbo_Prolog_Owners_Handbook_1987.pdf" rel="nofollow">https:&#x2F;&#x2F;ia802902.us.archive.org&#x2F;1&#x2F;items&#x2F;bitsavers_borlandtur...</a>
评论 #34739093 未加载
评论 #34738184 未加载
TomMaszover 2 years ago
I did some Prolog programming in school but I never really <i>got</i> the language coming from a Pascal&#x2F;C background. Your first language(s) really do affect your future learning.
timonokoover 2 years ago
Too long did not read. Me thinks Prolog should be parallel only now that we have AI-machines and such shit. It should starts every direction immediately and when some criteria is fulfilled it should start dropping answers without ever reaching the end.<p>fib(X,Y1+Y2):- fib(X-1,Y1),fib(X-2,Y2).<p>This should be legal kwestion and machine should start spewing numbers from zero to infinity.
mikewarotover 2 years ago
I wish I had never opened this thread... I hate Prolog with a burning passion now, I just thought it was weird earlier. It makes brainfuck look like a walk in the park.<p><pre><code> ?- write(10-2). 10-2 true. </code></pre> Why do I care? I figured out how to count to 5<p><pre><code> ?- foreach(between(0,5,N),writeln(N)). 0 1 2 3 4 5 true. </code></pre> Then since there&#x27;s no way to count down, I figured I&#x27;d just do a bit of math<p><pre><code> ?- foreach(between(0,5,N),writeln(5-N)). 5-0 5-1 5-2 5-3 5-4 5-5 true. </code></pre> I can not find a single way to force the evaluation before printing, it&#x27;s nuts!
评论 #34744332 未加载
评论 #34757062 未加载