Live data from Hacker News

The Simplicity of Prolog

bitsandtheorems.com

101–110 of 134 posts

Re: The Simplicity of Prolog

#102

Earlier quoted context omitted.

no. https://github.com/Datomic/codeq : last update to that repo was 12 years ago. it's JDK which I find unappealing. also, how close is it to Datalog? https://github.com/gns24/pydatomic : last update 11 years ago. and that's representative of pretty much anything regarding Datalog. So, I'll just stick to Prolog then. --- have you? would you recommend it?

I tried using Datomic Pro for a CMDB. I liked how logical queries were but I ended up going with Neo4j instead because finding paths between two nodes is incredibly useful in IT. https://central.sonatype.com/artifact/com.datomic/local/1.0....

mhm ... sounds like you don't know what you are talking about if you conflate Neo4j/Cypher with Datalog ... because "in IT".

Re: The Simplicity of Prolog

#103

Earlier quoted context omitted.

> 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

do you know what you are writing about? I mean have you actually done something with datalog? and then _which_ datalog? if yes, then you are probably someone working with it academically or the answer is no. because try to even set a toy project up with it (for the purpose of learning how to use it) and you'll quickly run into unmaintained interpreters, discussions of what datalog is and what not and you can choose b…

I have found two somewhat usable (your point still stands): soufflé (high performance but more limited) and DES, which works well for some simple personal data management, after some code massage (it’s written in Prolog). Any other recommendations? And since the prolog experts are here: what do you think about Ciao? Seems quite polished but also adventurous to (non-expert) me

Re: The Simplicity of Prolog

#104
post #93

Earlier quoted context omitted.

no. https://github.com/Datomic/codeq : last update to that repo was 12 years ago. it's JDK which I find unappealing. also, how close is it to Datalog? https://github.com/gns24/pydatomic : last update 11 years ago. and that's representative of pretty much anything regarding Datalog. So, I'll just stick to Prolog then. --- have you? would you recommend it?

Ok just to clarify, Datomic is a Clojure thing. It is free to use but closed source. It is an excellent database that is used, owned, and financed by Nubank, the largest and most rapidly growing bank in Brazil. It is not Datalog syntax but heavily inspired by Datalog. I'm throwing this in here just for clarification, I don't want to see Datomic as collateral damage in this conversation.

There is Datascript. I am not a Clojure guy, so it is not clear to me if it pulls datomic as a dependency.

Re: The Simplicity of Prolog

#105
post #34

Earlier quoted context omitted.

There are multiple ways to accomplish this, but the one that is the most straightforward is to simply make an object mapping of the type you are familiar with via AVL trees[1]. Easy way to get the "this.maze" semantics. You can get global context and local context via "blackboard"[2] semantics. However quite frankly the most powerful way to do this is not obvious because it doesn't translate well to other languages:…

Could you elaborate on all of these? For [1], you would either need to pass the AVL tree around or to have it as a global (which is not wanted), and instead pass the key (the "this" context which is different for different mazes) for the context around. For [2] again you have a global table (with copying semantics as for assert/retract? or maybe without copying? the docs don't say). But again you would need to pass a…

> Could you elaborate on all of these?

Certainly.

> For [1], you would either need to pass the AVL tree around or to have it as a global (which is not wanted), and instead pass the key (the "this" context which is different for different mazes) for the context around.

Not sure how tracking references is different here than any other programming language. Passing objects around is pretty common in OO programming. An AVL tree is just the underlying abstraction used to implement the object. You don't have to implicitly supply the "this" parameter to each "object" predicate if you don't want to -- you could insert that yourself via compilation (with term/goal expansion)[4] or interpretation (via meta-interpreters) if you were really interested in that level of syntactic sugar.

> For [2] again you have a global table (with copying semantics as for assert/retract? or maybe without copying? the docs don't say). But again you would need to pass a key around.

You could use global or local semantics as desirable. The blackboard has a global version that is persistent across application state or a local version that provides lexical context which unwinds on backtracking. Not sure how "passing a key around" is different than most other forms of programming, but if you wanted to compile it away, please review the techniques listed above.

> [3] is... yeah. I mean, sure, you could demonstrate this with a toy metainterpreter on a toy example. But do you really want to run your whole application inside a metainterpreter?

A "toy" meta-interpreter? Meta-interpreters are as fundamental to Prolog as for-loops are to Python. Certain applications, such as games, are run "entirely inside a loop", so I'm not sure how this criticism applies. You can run as much or as little of your application inside a meta-interpreter as you want. The value proposition of Prolog is that the simple homoiconic syntax allows for powerful meta-interpretation. I'd suggest checking out the video I linked to in [3] if you have doubts on that topic.

> One could also abuse DCG syntax, with the context being some state object instead of a DCG list.

State transitions (a sequence of states) are a great use for DCG syntax! I wouldn't call that "abuse".

> A more practical way would be Logtalk-like code generation. The most practical way would be actual Logtalk.

If you are willing to give up the most powerful features of Prolog, sure.

> Unfortunately, last I heard Scryer refused to host Logtalk for no real reason.

Hmm, I wonder if that's the real story :)

[4]: Please see Section 3 of my talk if you are interested in a more thorough explanation of goal/term expansion. https://docs.google.com/presentation/d/e/2PACX-1vR4Q0Ohs66mj...

Re: The Simplicity of Prolog

#106
post #93

Earlier quoted context omitted.

Ok just to clarify, Datomic is a Clojure thing. It is free to use but closed source. It is an excellent database that is used, owned, and financed by Nubank, the largest and most rapidly growing bank in Brazil. It is not Datalog syntax but heavily inspired by Datalog. I'm throwing this in here just for clarification, I don't want to see Datomic as collateral damage in this conversation.

There is Datascript. I am not a Clojure guy, so it is not clear to me if it pulls datomic as a dependency.

Datascript is very similar to Datomic, except that it runs in ClojureScript and is an in-memory datastore with no concept of history or point-in-time queries. The schemas are also much looser than Datomic.

Otherwise, many syntax and semantics are similar.

No dependency on Datomic as Datomic is Java and DataScript is JavaScript.

Re: The Simplicity of Prolog

#107

Earlier quoted context omitted.

Could you elaborate on all of these? For [1], you would either need to pass the AVL tree around or to have it as a global (which is not wanted), and instead pass the key (the "this" context which is different for different mazes) for the context around. For [2] again you have a global table (with copying semantics as for assert/retract? or maybe without copying? the docs don't say). But again you would need to pass a…

> Could you elaborate on all of these? Certainly. > For [1], you would either need to pass the AVL tree around or to have it as a global (which is not wanted), and instead pass the key (the "this" context which is different for different mazes) for the context around. Not sure how tracking references is different here than any other programming language. Passing objects around is pretty common in OO programming. An A…

> You don't have to implicitly supply the "this" parameter to each "object" predicate if you don't want to [...] if you were really interested in that level of syntactic sugar.

Given that the original "feature request" (https://news.ycombinator.com/item?id=42829985) was this:

>>>> There is no concept of "current maze", like in OO you would have with this.maze, or in Haskell you would do with a reader monad. As a result, all the "internal" predicates in a module get full of parameters all they do is pass around until some final predicate uses it to do some calculation.

I would say that yes, the OP wanted exactly that level of syntactic sugar and your previous suggestions [1] and [2] were addressing something else entirely.

> you could insert that yourself via compilation (with term/goal expansion)[4]

Yes, that's why I meant above by "Logtalk-like code generation". Suggesting that I study the thing that I suggested feels a little condescending.

Re: The Simplicity of Prolog

#108

Earlier quoted context omitted.

Not specifically aimed at this comment, but it looks like in most Prolog threads here, many commenters seems to plugging in Scryer Prolog, but perhaps, SWI is the most 'batteries included' and mature Prolog implementation for people not familiar with Prolog to try out .

SWI Prolog 7 added "X = Dict.key" syntax and that use of "." makes it fundamentally incompatible, ISO standard breaking, backwards incompatible to previous Prologs, sideways incompatible to other Prologs. This is a worse sin in Prolog than it seems at a glance, because one of the strengths Prolog has is code-is-data / data-is-code metaprogramming. That includes exporting code as Prolog terms (use cases you might use…

> SWI 7 can't guarantee to read all SWI 6 code

> Code written 30 years ago which uses the dot in the old standard way might trigger SWI to try and read it in the Dict.key way and fail.

Why would they do that? SWI 7 reading SWI 6 or ISO prolog code should be rather trivial, shouldn't it?

Re: The Simplicity of Prolog

#109
post #98

Earlier quoted context omitted.

Prolog predicates are not first class values. Data structures are not abstract. Compare both with any modern lisp or better with functional languages. Mapping and filtering is awkward. Arithmetic is awkward. Indexing and search strategies are not under programmer control. Modes are awkward. Cut and dynamic assert of global facts are abominations which undermine logical reasoning. Prolog programmers often write metaci…

A lot of these comments don't make any sense to me. > Prolog predicates are not first class values. Predicates are trivially called, even as variables, with the `call/N` metapredicate. > Mapping and filtering is awkward In what sense? The declarative semantics...? > Arithmetic is awkward In what sense...? Have you seen clpz? > The CLP examples aren't integrated with Prolog's Horn clause resolution model In what sense…

> Predicates are trivially called, even as variables, with the `call/N` metapredicate.

Yes, that is the definition of "predicates are not first class values". Some things can be called without call/N. Other things can not be called without call/N. These are two separate classes of things. Both of these classes cannot be the first class.

Re: The Simplicity of Prolog

#110

Earlier quoted context omitted.

I tried using Datomic Pro for a CMDB. I liked how logical queries were but I ended up going with Neo4j instead because finding paths between two nodes is incredibly useful in IT. https://central.sonatype.com/artifact/com.datomic/local/1.0....

mhm ... sounds like you don't know what you are talking about if you conflate Neo4j/Cypher with Datalog ... because "in IT".

I'm fully aware they are very different things. I'm just saying I have tried using datomic and I really like it's query language but it cannot find a path between two objects like Neo4j which is a killer feature in a CMDB. My dream DB would be a hybrid of Neo4j and Datomic.

An example of where Neo4j really shines is I found a site with BGP route dumps. The file contains over 57 million very redundant Autonomous System paths that are just sequences of a IP prefix and the AS path it is reachable by. By loading each IP prefix and AS hop as

(Prefix)-[:ANNOUNCED_BY]->[:AS]-[:BGP_NEXT_HOP]->[:AS]

I can easily trace paths from one prefix to another by going

MATCH path = (p1:Prefix)-[:*]->(p2:Prefix) return path

which will return which AS announce the prefixes and all BGP paths between them. It really is very powerful.

Post reply on HN