Documentation ¶
Index ¶
- Variables
- func Arg(arg, term, value Term, k func() (bool, error)) (bool, error)
- func AtomChars(atom, chars Term, k func() (bool, error)) (bool, error)
- func AtomCodes(atom, codes Term, k func() (bool, error)) (bool, error)
- func AtomConcat(atom1, atom2, atom3 Term, k func() (bool, error)) (bool, error)
- func AtomLength(atom, integer Term, k func() (bool, error)) (bool, error)
- func CharCode(char, code Term, k func() (bool, error)) (bool, error)
- func Compare(order, term1, term2 Term, k func() (bool, error)) (bool, error)
- func Contains(t, s Term) bool
- func CopyTerm(in, out Term, k func() (bool, error)) (bool, error)
- func Cut(k func() (bool, error)) (bool, error)
- func Done() (bool, error)
- func Each(list Term, f func(elem Term) error) error
- func Functor(term, name, arity Term, k func() (bool, error)) (bool, error)
- func NumberChars(num, chars Term, k func() (bool, error)) (bool, error)
- func NumberCodes(num, chars Term, k func() (bool, error)) (bool, error)
- func Repeat(k func() (bool, error)) (bool, error)
- func SubAtom(atom, before, length, after, subAtom Term, k func() (bool, error)) (bool, error)
- func Throw(t Term, _ func() (bool, error)) (bool, error)
- func TypeAtom(t Term, k func() (bool, error)) (bool, error)
- func TypeCompound(t Term, k func() (bool, error)) (bool, error)
- func TypeFloat(t Term, k func() (bool, error)) (bool, error)
- func TypeInteger(t Term, k func() (bool, error)) (bool, error)
- func TypeVar(t Term, k func() (bool, error)) (bool, error)
- func Unify(t1, t2 Term, k func() (bool, error)) (bool, error)
- func UnifyWithOccursCheck(t1, t2 Term, k func() (bool, error)) (bool, error)
- func Univ(term, list Term, k func() (bool, error)) (bool, error)
- type Atom
- type Compound
- type Engine
- func (e *Engine) Describe(v *Variable) string
- func (e *Engine) Exec(s string) error
- func (e *Engine) Query(s string, cb func(vars []*Variable) bool) (bool, error)
- func (e *Engine) Register0(name string, p func(func() (bool, error)) (bool, error))
- func (e *Engine) Register1(name string, p func(Term, func() (bool, error)) (bool, error))
- func (e *Engine) Register2(name string, p func(Term, Term, func() (bool, error)) (bool, error))
- func (e *Engine) Register3(name string, p func(Term, Term, Term, func() (bool, error)) (bool, error))
- func (e *Engine) Register4(name string, ...)
- func (e *Engine) Register5(name string, ...)
- type EngineState
- func (e *EngineState) Abolish(t Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) Asserta(t Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) Assertz(t Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) BagOf(template, goal, bag Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) Call(goal Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) Catch(goal, catcher, recover Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) CharConversion(char1, char2 Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) Clause(head, body Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) Close(stream, options Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) CurrentCharConversion(char1, char2 Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) CurrentInput(stream Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) CurrentOp(precedence, typ, name Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) CurrentOutput(stream Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) CurrentPredicate(pf Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) CurrentPrologFlag(flag, value Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) FlushOutput(stream Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) GetByte(stream, byt Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) GetCode(stream, code Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) Halt(n Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) Op(precedence, typ, name Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) Open(filename, mode, stream, options Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) PeekByte(stream, byt Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) PeekCode(stream, code Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) PutByte(stream, byt Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) PutCode(stream, code Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) ReadTerm(stream, term, options Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) Retract(t Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) SetInput(stream Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) SetOf(template, goal, bag Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) SetOutput(stream Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) SetPrologFlag(flag, value Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) SetStreamPosition(stream, pos Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) StreamProperty(stream, property Term, k func() (bool, error)) (bool, error)
- func (e *EngineState) WriteTerm(stream, term, options Term, k func() (bool, error)) (bool, error)
- type Exception
- type Float
- type FunctionSet
- func (fs FunctionSet) Equal(lhs, rhs Term, k func() (bool, error)) (bool, error)
- func (fs FunctionSet) GreaterThan(lhs, rhs Term, k func() (bool, error)) (bool, error)
- func (fs FunctionSet) GreaterThanOrEqual(lhs, rhs Term, k func() (bool, error)) (bool, error)
- func (fs FunctionSet) Is(lhs, rhs Term, k func() (bool, error)) (bool, error)
- func (fs FunctionSet) LessThan(lhs, rhs Term, k func() (bool, error)) (bool, error)
- func (fs FunctionSet) LessThanOrEqual(lhs, rhs Term, k func() (bool, error)) (bool, error)
- func (fs FunctionSet) NotEqual(lhs, rhs Term, k func() (bool, error)) (bool, error)
- type Integer
- type Operator
- type Operators
- type Parser
- type Stream
- type Term
- type Variable
- type WriteTermOptions
Constants ¶
This section is empty.
Variables ¶
var DefaultFunctionSet = FunctionSet{ Unary: map[Atom]func(Term) (Term, error){ "-": unaryNumber(func(i int64) int64 { return -1 * i }, func(n float64) float64 { return -1 * n }), "abs": unaryFloat(math.Abs), "atan": unaryFloat(math.Atan), "ceiling": unaryFloat(math.Ceil), "cos": unaryFloat(math.Cos), "exp": unaryFloat(math.Exp), "sqrt": unaryFloat(math.Sqrt), "sign": unaryNumber(sgn, sgnf), "float": unaryFloat(func(n float64) float64 { return n }), "floor": unaryFloat(math.Floor), "log": unaryFloat(math.Log), "sin": unaryFloat(math.Sin), "truncate": unaryFloat(math.Trunc), "round": unaryFloat(math.Round), "\\": unaryInteger(func(i int64) int64 { return ^i }), }, Binary: map[Atom]func(Term, Term) (Term, error){ "+": binaryNumber(func(i, j int64) int64 { return i + j }, func(n, m float64) float64 { return n + m }), "-": binaryNumber(func(i, j int64) int64 { return i - j }, func(n, m float64) float64 { return n - m }), "*": binaryNumber(func(i, j int64) int64 { return i * j }, func(n, m float64) float64 { return n * m }), "/": binaryFloat(func(n float64, m float64) float64 { return n / m }), "//": binaryInteger(func(i, j int64) int64 { return i / j }), "rem": binaryInteger(func(i, j int64) int64 { return i % j }), "mod": binaryInteger(func(i, j int64) int64 { return (i%j + j) % j }), "**": binaryFloat(math.Pow), ">>": binaryInteger(func(i, j int64) int64 { return i >> j }), "<<": binaryInteger(func(i, j int64) int64 { return i << j }), "/\\": binaryInteger(func(i, j int64) int64 { return i & j }), "\\/": binaryInteger(func(i, j int64) int64 { return i | j }), }, }
Functions ¶
func UnifyWithOccursCheck ¶
Types ¶
type Atom ¶
type Atom string
Atom is a prolog atom.
type Compound ¶
Compound is a prolog compound.
type Engine ¶
type Engine struct {
EngineState
}
Engine is a Prolog interpreter. The zero value for Engine is a valid interpreter without any builtin predicates.
func NewEngine ¶
NewEngine creates an Engine with user_input, user_output and builtin predicates. It is encouraged user_input to be *bufio.Reader since it enables a wide range of input operations.
func (*Engine) Query ¶
Query executes a prolog query and calls the callback function for each solution. Returning true from the callback halts the iteration.
func (*Engine) Register3 ¶
func (e *Engine) Register3(name string, p func(Term, Term, Term, func() (bool, error)) (bool, error))
Register3 registers a predicate of arity 3.
type EngineState ¶
type EngineState struct { // BeforeHalt is a hook which gets triggered right before halt/0 or halt/1. BeforeHalt []func() // contains filtered or unexported fields }
EngineState is an internal state of Engine, a subject to many builtin predicates.
func (*EngineState) CharConversion ¶
func (*EngineState) CurrentCharConversion ¶
func (*EngineState) CurrentInput ¶
func (*EngineState) CurrentOutput ¶
func (*EngineState) CurrentPredicate ¶
func (*EngineState) CurrentPrologFlag ¶
func (*EngineState) FlushOutput ¶
func (*EngineState) SetPrologFlag ¶
func (*EngineState) SetStreamPosition ¶
func (*EngineState) StreamProperty ¶
type Float ¶
type Float float64
Float is a prolog floating-point number.
type FunctionSet ¶
type FunctionSet struct { Unary map[Atom]func(x Term) (Term, error) Binary map[Atom]func(x, y Term) (Term, error) }
func (FunctionSet) GreaterThan ¶
func (FunctionSet) GreaterThanOrEqual ¶
func (FunctionSet) LessThanOrEqual ¶
type Integer ¶
type Integer int64
Integer is a prolog integer.
type Operators ¶
type Operators []Operator
Operators are a list of operators sorted in a descending order of precedence.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser turns bytes into Term.
type Term ¶
type Term interface { fmt.Stringer WriteTerm(io.Writer, WriteTermOptions) error Unify(Term, bool) bool Copy() Term }
Term is a prolog term.
func PrincipalFunctor ¶
PrincipalFunctor returns a compound of name/arity.
func Resolve ¶
Resolve follows the variable chain and returns the first non-variable term or the last free variable.