Live data from Hacker News

An embeddable Prolog scripting language for Go

github.com

1–10 of 36 posts

Re: An embeddable Prolog scripting language for Go

#5
post #2

What does the interop with go look like? Is there a story for writing prolog queries over go data structures and iterating the results. If this could be made ergonomic, it’d be very cool.

From the given example, basically the same as `database/sql` - you `Exec` or `Query` a Prolog doodah, iterate over the solutions with `Next`, and `Scan` the results into your structs.

Re: An embeddable Prolog scripting language for Go

#6

What are the trade offs of embedding a Prolog interpreter versus having a library that implements prolog logic without having to have another language. Are there any high quality prolog as a library implementations in languages such as Rust, C++, Java, Go?

> What are the trade offs of embedding a Prolog interpreter versus having a library that implements prolog logic without having to have another language.

A library that implements Prolog logic is an interpreter.

The difference here is that Prolog source code is passed in as a string as opposed to having an embedded domain specific language where you construct the abstract syntax tree.

Go is a very simple language and it doesn't have the kind of metaprogramming facilities that are typically used for creating embedded DSLs. Hence it's a reasonable choice to just have a parser and pass in the logic code as a string. There's probably a way to pass in the AST as well but it may not be very ergonomic.

Parsing the source and constructing the AST isn't very expensive and it's only done once per program, so the runtime cost isn't huge.

There are Prolog and Prolog-like embeddable interpreters and logic programming systems for many other prorgamming languages, including Rust, C++ and Java.

The best known ones are Clojure's core.logic (based on the logic interpreter in the SICP book) and Minikanren.

Re: An embeddable Prolog scripting language for Go

#7
post #6

What are the trade offs of embedding a Prolog interpreter versus having a library that implements prolog logic without having to have another language. Are there any high quality prolog as a library implementations in languages such as Rust, C++, Java, Go?

> What are the trade offs of embedding a Prolog interpreter versus having a library that implements prolog logic without having to have another language. A library that implements Prolog logic is an interpreter. The difference here is that Prolog source code is passed in as a string as opposed to having an embedded domain specific language where you construct the abstract syntax tree. Go is a very simple language and…

Indeed. Text is "unreasonably efficient" in this case. Passing a struct is easy enough in go, but that's all it can do for you. So you'd have to pass arguments like PLClauseList{PLLoadClause{...}, ..., PLFact{Head: PLAtom{"human"}, Arguments: PLArgList{PLAtom{"socrates"}}}, ...}. Unwieldy, unreadable, and hard to edit.

Re: An embeddable Prolog scripting language for Go

#8

What are the trade offs of embedding a Prolog interpreter versus having a library that implements prolog logic without having to have another language. Are there any high quality prolog as a library implementations in languages such as Rust, C++, Java, Go?

IMHO you loose a lot of expresiveness. Real Prolog code is not just simple rules and facts. They can be more complex than that. For example, in my case, I'd like to use DCGs a lot, which are a bit difficult to translate using "normal languages" constructs. Many Prolog systems implement DCGs with Prolog macros because Prolog is homoiconic, which most normal languages aren't (Lisp is homoiconic too).

Also "logic" arithmetic (clpz, clpfd,...) is not the one that comes with normal languages and that breaks a lot of logical properties. Doing the sum of two variables in Java side will not respect logical properties. Standard is/2 in Prolog is also bad, but at least you can replace it with #= and that's it.

Re: An embeddable Prolog scripting language for Go

#9
I've been keeping an eye on this to use for the rules engine in a card game I'm writing[0]. Very excited to get back into using Prolog; I think it's fallen by the wayside a bit in the last decade or two but there's some sectors that still have strong arguments for using it if not as the main language then at least an extension language.

[0] Inspired by a HN comment a while back about Gleemin, the MTG expert engine in Prolog: https://github.com/stassa/Gleemin

Re: An embeddable Prolog scripting language for Go

#10
post #9

I've been keeping an eye on this to use for the rules engine in a card game I'm writing[0]. Very excited to get back into using Prolog; I think it's fallen by the wayside a bit in the last decade or two but there's some sectors that still have strong arguments for using it if not as the main language then at least an extension language. [0] Inspired by a HN comment a while back about Gleemin, the MTG expert engine in…

Oh, hey, that's cool! Good luck with your card game, I hope we'll get to see a "Show HN" soon (no pressure!) :)
Post reply on HN