trealla

package module
v0.0.0-...-03f7e30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFailure = fmt.Errorf("trealla: query failed")

ErrFailure is returned when a query fails (when it finds no solutions).

Functions

This section is empty.

Types

type Answer

type Answer struct {
	// Query is the original query goal.
	Query string
	// Answers are the solutions (substitutions) for a successful query.
	Answers []Solution
	// Output is captured stdout text from this query.
	Output string
}

Answer is a query result.

type Compound

type Compound struct {
	// Functor is the principal functor of the compound.
	// Example: the Functor of foo(bar) is "foo".
	Functor string
	// Args are the arguments of the compound.
	Args []Term
}

Compound is a Prolog compound type.

func (Compound) Indicator

func (c Compound) Indicator() string

Indicator returns the procedure indicator of this compound in Functor/Arity format.

func (Compound) String

func (c Compound) String() string

String returns a Prolog-ish representation of this Compound.

type ErrThrow

type ErrThrow struct {
	// Ball is the term thrown by throw/1.
	Ball Term
}

ErrThrow is returned when an exception is thrown during a query.

func (ErrThrow) Error

func (err ErrThrow) Error() string

type Option

type Option func(*prolog)

Option is an optional parameter for New.

func WithMapDir

func WithMapDir(alias, dir string) Option

WithMapDir sets alias to point to directory dir, granting access to it. This can be called multiple times with different aliases.

func WithPreopenDir

func WithPreopenDir(dir string) Option

WithPreopenDir sets the preopen directory to dir, granting access to it. Calling this again will overwrite it. More or less equivalent to `WithMapDir(dir, dir)`.

type Prolog

type Prolog interface {
	// Query executes a query.
	Query(ctx context.Context, query string) (Answer, error)
}

Prolog is a Prolog interpreter.

func New

func New(opts ...Option) (Prolog, error)

New creates a new Prolog interpreter.

type Solution

type Solution map[string]Term

Solution is a mapping of variable names to substitutions. In other words, it's one answer to a query.

func (*Solution) UnmarshalJSON

func (sol *Solution) UnmarshalJSON(bs []byte) error

UnmarshalJSON implements the encoding/json.Marshaler interface.

type Term

type Term = any

Term is a Prolog term.

One of the following types:

  • string
  • int64
  • float64
  • Compound
  • Variable

type Variable

type Variable string

Variable is an unbound Prolog variable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL