trealla-go GoDoc

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

License

MIT. See ATTRIBUTION as well.

See also

GitHub

View Github