24 comments

[ 3.4 ms ] story [ 45.7 ms ] thread
[flagged]
Maybe they just had fun exploring the topic?
Sure, being excited about something is fine.

But I see so many of these articles/blog posts where people claim to be implementing Datalog but are just implementing a form of relational algebra. This apparently just begets further confusion and misinformation.

This is like seeing an article about how to implement context free parsing and finding one about implementing regular expressions with DFAs.

Is it really too much to ask for people to do basic fact checking before publishing? Or with the age of generative AI are we giving up on that?

I think it's because Datomic is most devs' only exposure to anything in the Prolog family, and rules (and especially recursion) aren't emphasized. Which is a shame, because Prolog, ASP and Datalog are phenomenally useful.
Can you fill us in on the differences?

I doubt this has anything to do with generative AI, unless it was written by GPT3 and if so it did a great job. GPT4 would be released over a year after this was released.

I didn’t say this was written by generative AI. I just wondered if people are more willing to accept and forgive completely wrong information because of it.
You’ve bled so many pixels complaining about wrong information. Can you please provide an informative and accurate link that explains a similar implementation?
I second the disgruntled commenter's feelings. This has nothing to do with Datalog.

Here are three accurate and sound Datalog implementations: 1: https://github.com/ekzhang/crepe 2: https://github.com/s-arash/ascent 3: https://github.com/brurucy/micro-datalog

Thank you!

I didn't know this had nothing to do with Datalog - just extremely annoying (and not your fault) that we are 7 comments deep.

I think we called it C&C back in the day, constructive criticism. Just was missing the constructive part.

Hi pests, I don't think the criticism in the comments gives a full picture.

I wrote about a particular flavor of datalog, in common use today. [1] [2]. The earliest representation I know which matches the syntax of my essay, was in SICP [3]

There's another, more academic form of datalog which looks a lot like prolog. There's lots of similarities and [2] mentions them.

[1] https://github.com/tonsky/datascript [2] https://docs.datomic.com/pro/query/query.html [3] https://sarabander.github.io/sicp/html/4_002e4.xhtml

There is no such thing as "a more academic form of Datalog". There is only one Datalog.

Both Datascript and Datomic support recursion. In SICP it too talks about how rules can be defined recursively.

If there is no recursion, then it's just SQL without negation.

What makes it Datalog is the recursive part.

Plus, the "triples" part of what you call "Datalog", as it is explained on Datomic's documentation, is nothing related to Datalog at all. It's just a convenient format to ensure that all data is in a RDF-inspired format. Semantics aside, it makes it easier to build indexes and for it to be performant, compared to multi-relation unbounded-arity Datalog.

> The author should be embarrassed and ashamed that they put out such a poorly researched article.

Cue the “Your music is bad and you should feel bad!” meme.

Seriously, though, providing constructive feedback is fine, but telling people they should be ashamed and embarrassed is a step too far.

You haven’t seen as many of these completely misinformed implementations claiming to be Datalog when they really aren’t.
I first saw "triples" in the context of RDF & the "semantic web" a couple decades ago, and it drove me batty, because really it's just a weird roundabout way of saying "binary relations" but sounding novel....

This article saying it's like "one big table" ... huh? No, it's multiple binary relations. Sure, you could formulate that as one big ternary relation and call it triples? Somehow? Oof. But why?

In any case, binary relations are not intrinsic to Datalog, just to the form of it that Datomic implements. It's entirely possible to make "a datalog" that uses n-ary relations (or to compose binary relations into something that looks n-ary).

(comment deleted)
Beautiful article and explanation. I have been in this career for almost 2 decades and this is the first time I hear about Datalog and triples, and it is such an elegant, interesting idea!

Thanks for teaching an old dog new tricks :) Where to do from here? Any other triple-based databases out there?

EDIT: please ignore the absolutely rude and entitled sibling comment.

Except this article has taught you nothing about Datalog. You’d have learned more from Wikipedia.

It is interesting to know I’m “entitled” for wanting people to provide accurate information online, rather than misinforming and confusing people.

Brightened my day to read this, thank you sph :)
I love this kind of article. Seeing that you can get somewhere (NOT a fullblown datalog, but isn't that obvious?) with a few lines of code, is truly a nice way to ease people into something. Going for a full implementation would make people almost immediately cry, so this is a lot better as 'first contact'.
Except this isn’t Datalog. It’s just a poor quality implementation of relational algebra. This article did not actually teach you anything about Datalog, just continued to propagate misinformation.
I see what you mean, but I do see it as a little introduction to knowledge (and interest) you need to actual go for something more advanced. But I see what you mean. Here (0) is a quite straightforward implementation that would make you happier I guess. But yeah, shouldn't be called Datalog, I agree.

0 https://harvardpl.github.io/AbcDatalog/

So I asked ai to make a datalog implementation in JavaScript.

// In-memory storage for voted users const votedUsers = new Set();

// Datalog-like rules function eligible_to_vote(user) { return isUserOldEnough(user) && isCanadianCitizen(user); }

function voted(user, bill) { return votedUsers.has(`${user}_${bill}`); }

// Custom rules function isUserOldEnough(user) { // Assuming age is stored in user object return user.age >= 18; }

function isCanadianCitizen(user) { // Assuming citizenship information is stored in user object return user.citizenship === 'Canada'; }

function recordVote(user, bill) { // Record that the user has voted on the specified bill votedUsers.add(`${user}_${bill}`); }

// Example usage const user = { name: "user123", age: 25, citizenship: "Canada", };

const bill = "bill456";

if (eligible_to_vote(user)) { console.log("User is eligible to vote.");

  if (!voted(user.name, bill)) {
    console.log("User can vote on this bill.");
    // Implement further logic for voting...

    // Record the vote
    recordVote(user.name, bill);
  } else {
    console.log("User has already voted on this bill.");
  }
} else { console.log("User is not eligible to vote."); }
How is the language being presented connected to Datalog whatsoever? It uses a very alien syntax, and has no mention of Datalog's defining feature, recursion that is always guaranteed to terminate.

Here's an __actual__ small (and very fast) full blown datalog engine: https://github.com/brurucy/micro-datalog