trealla-go 
import "github.com/trealla-prolog/go/trealla"
Prolog interface for Go using Trealla Prolog and Wasmer. It’s pretty fast. Not as fast as native Trealla, but pretty dang fast (2-5x slower than native).
Development Status: alpha ðŸ¤
Caveats
- Alpha status, API will change.
- Queries are findall’d and won’t return answers until they terminate.
- Doesn’t work on Windows (wasmer-go issue).
- Works great on WSL.
- Currently interpreters are ephemeral, so you have to reconsult everything each query (working on this).
Usage
This library uses WebAssembly to run Trealla, executing Prolog queries in an isolated environment.
import "github.com/trealla-prolog/go/trealla"
func main() {
// load the interpreter and (optionally) grant access to the current directory
pl := trealla.New(trealla.WithPreopen("."))
// run a query; cancel context to abort it
answer, err := pl.Query(ctx, "member(X, [1, foo(bar), c]).")
// get the second substitution (answer) for X
x := answer.Solutions[1]["X"] // trealla.Compound{Functor: "foo", Args: ["bar"]}
}
Thanks
- Andrew Davison (@infradig) and other contributors to Trealla Prolog.
- Jos De Roo (@josd) for test cases and encouragement.
- Aram Panasenco (@panasenco) for his JSON library.
License
MIT. See ATTRIBUTION as well.
See also
- ichiban/prolog is a pure Go Prolog.
- guregu/pengine is a Pengines (SWI-Prolog) library for Go.