Documentation ¶
Index ¶
- Constants
- Variables
- func Contains(t, s Term, env *Env) bool
- func WriteTerm(w io.Writer, t Term, opts *WriteOptions, env *Env) error
- type AltIterator
- type AnyIterator
- type Atom
- type Compound
- type EOFAction
- type Env
- func (e *Env) Bind(k Variable, v Term) *Env
- func (e *Env) Compare(x, y Term) Order
- func (e *Env) FreeVariables(ts ...Term) []Variable
- func (e *Env) Lookup(k Variable) (Term, bool)
- func (e *Env) Resolve(t Term) Term
- func (e *Env) Set(ts ...Term) Term
- func (e *Env) Simplify(t Term) Term
- func (e *Env) Unify(x, y Term, occursCheck bool) (*Env, bool)
- type EvaluableFunctors
- func (e EvaluableFunctors) Equal(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise
- func (e EvaluableFunctors) GreaterThan(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise
- func (e EvaluableFunctors) GreaterThanOrEqual(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise
- func (e EvaluableFunctors) Is(result, expression Term, k func(*Env) *Promise, env *Env) *Promise
- func (e EvaluableFunctors) LessThan(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise
- func (e EvaluableFunctors) LessThanOrEqual(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise
- func (e EvaluableFunctors) NotEqual(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise
- type Exception
- func DomainError(validDomain ValidDomain, culprit Term, env *Env) Exception
- func EvaluationError(ev ExceptionalValue, env *Env) Exception
- func ExistenceError(objectType ObjectType, culprit Term, env *Env) Exception
- func InstantiationError(env *Env) Exception
- func NewException(term Term, env *Env) Exception
- func PermissionError(operation Operation, permissionType PermissionType, culprit Term, env *Env) Exception
- func RepresentationError(limit Flag, env *Env) Exception
- func ResourceError(resource Resource, env *Env) Exception
- func SyntaxError(err error, env *Env) Exception
- func SystemError(err error) Exception
- func TypeError(validType ValidType, culprit Term, env *Env) Exception
- type ExceptionalValue
- type Flag
- type Float
- type Integer
- type Lexer
- type ListIterator
- type Number
- func Abs(x Number) (Number, error)
- func Acos(x Number) (Number, error)
- func Add(x, y Number) (Number, error)
- func AsFloat(x Number) (Number, error)
- func Asin(x Number) (Number, error)
- func Atan(x Number) (Number, error)
- func Atan2(y, x Number) (Number, error)
- func BitwiseAnd(b1, b2 Number) (Number, error)
- func BitwiseComplement(b1 Number) (Number, error)
- func BitwiseLeftShift(n, s Number) (Number, error)
- func BitwiseOr(b1, b2 Number) (Number, error)
- func BitwiseRightShift(n, s Number) (Number, error)
- func Ceiling(x Number) (Number, error)
- func Cos(x Number) (Number, error)
- func Div(x, y Number) (Number, error)
- func Exp(x Number) (Number, error)
- func FloatFractionalPart(x Number) (Number, error)
- func FloatIntegerPart(x Number) (Number, error)
- func Floor(x Number) (Number, error)
- func IntDiv(x, y Number) (Number, error)
- func IntFloorDiv(x, y Number) (Number, error)
- func IntegerPower(x, y Number) (Number, error)
- func Log(x Number) (Number, error)
- func Max(x, y Number) (Number, error)
- func Min(x, y Number) (Number, error)
- func Mod(x, y Number) (Number, error)
- func Mul(x, y Number) (Number, error)
- func Neg(x Number) (Number, error)
- func Pos(x Number) (Number, error)
- func Power(x, y Number) (Number, error)
- func Rem(x, y Number) (Number, error)
- func Round(x Number) (Number, error)
- func Sign(x Number) (Number, error)
- func Sin(x Number) (Number, error)
- func Sqrt(x Number) (Number, error)
- func Sub(x, y Number) (Number, error)
- func Tan(x Number) (Number, error)
- func Truncate(x Number) (Number, error)
- func Xor(x, y Number) (Number, error)
- type ObjectType
- type Operation
- type Order
- type ParsedVariable
- type Parser
- type PermissionType
- type ProcedureIndicator
- type Promise
- func AcyclicTerm(t Term, k func(*Env) *Promise, env *Env) *Promise
- func Append(xs, ys, zs Term, k func(*Env) *Promise, env *Env) *Promise
- func Arg(nth, t, arg Term, k func(*Env) *Promise, env *Env) *Promise
- func AtomChars(atom, chars Term, k func(*Env) *Promise, env *Env) *Promise
- func AtomCodes(atom, codes Term, k func(*Env) *Promise, env *Env) *Promise
- func AtomConcat(atom1, atom2, atom3 Term, k func(*Env) *Promise, env *Env) *Promise
- func AtomLength(atom, length Term, k func(*Env) *Promise, env *Env) *Promise
- func Between(lower, upper, value Term, k func(*Env) *Promise, env *Env) *Promise
- func Bool(ok bool) *Promise
- func Catch(recover func(error) *Promise, k func(context.Context) *Promise) *Promise
- func CharCode(char, code Term, k func(*Env) *Promise, env *Env) *Promise
- func Compare(order, term1, term2 Term, k func(*Env) *Promise, env *Env) *Promise
- func CopyTerm(in, out Term, k func(*Env) *Promise, env *Env) *Promise
- func Cut(parent *Promise, k func(context.Context) *Promise) *Promise
- func Delay(k ...func(context.Context) *Promise) *Promise
- func Environ(key, value Term, k func(*Env) *Promise, env *Env) *Promise
- func Error(err error) *Promise
- func Functor(t, name, arity Term, k func(*Env) *Promise, env *Env) *Promise
- func Halt(n Term, k func(*Env) *Promise, env *Env) *Promise
- func KeySort(pairs, sorted Term, k func(*Env) *Promise, env *Env) *Promise
- func Length(list, length Term, k func(*Env) *Promise, env *Env) *Promise
- func Nth0(n, list, elem Term, k func(*Env) *Promise, env *Env) *Promise
- func Nth1(n, list, elem Term, k func(*Env) *Promise, env *Env) *Promise
- func NumberChars(num, chars Term, k func(*Env) *Promise, env *Env) *Promise
- func NumberCodes(num, codes Term, k func(*Env) *Promise, env *Env) *Promise
- func Repeat(k func(context.Context) *Promise) *Promise
- func SkipMaxList(skip, max, list, suffix Term, k func(*Env) *Promise, env *Env) *Promise
- func Sort(list, sorted Term, k func(*Env) *Promise, env *Env) *Promise
- func SubAtom(atom, before, length, after, subAtom Term, k func(*Env) *Promise, env *Env) *Promise
- func SubsumesTerm(general, specific Term, k func(*Env) *Promise, env *Env) *Promise
- func Succ(x, s Term, k func(*Env) *Promise, env *Env) *Promise
- func TermVariables(term, vars Term, k func(*Env) *Promise, env *Env) *Promise
- func Throw(ball Term, _ func(*Env) *Promise, env *Env) *Promise
- func TypeAtom(t Term, k func(*Env) *Promise, env *Env) *Promise
- func TypeCompound(t Term, k func(*Env) *Promise, env *Env) *Promise
- func TypeFloat(t Term, k func(*Env) *Promise, env *Env) *Promise
- func TypeInteger(t Term, k func(*Env) *Promise, env *Env) *Promise
- func TypeVar(t Term, k func(*Env) *Promise, env *Env) *Promise
- func Unify(x, y Term, k func(*Env) *Promise, env *Env) *Promise
- func UnifyWithOccursCheck(x, y Term, k func(*Env) *Promise, env *Env) *Promise
- func Univ(t, list Term, k func(*Env) *Promise, env *Env) *Promise
- type Resource
- type SeqIterator
- type State
- func (state *State) Abolish(pi Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Assert(t Term, env *Env) error
- func (state *State) Asserta(t Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Assertz(t Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) BagOf(template, goal, instances Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) BuiltIn(pi Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Call(goal Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Call1(closure, arg1 Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Call2(closure, arg1, arg2 Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Call3(closure, arg1, arg2, arg3 Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Call4(closure, arg1, arg2, arg3, arg4 Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Call5(closure, arg1, arg2, arg3, arg4, arg5 Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Call6(closure, arg1, arg2, arg3, arg4, arg5, arg6 Term, k func(*Env) *Promise, ...) *Promise
- func (state *State) Call7(closure, arg1, arg2, arg3, arg4, arg5, arg6, arg7 Term, k func(*Env) *Promise, ...) *Promise
- func (state *State) CallNth(goal, nth Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Catch(goal, catcher, recover Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) CharConversion(inChar, outChar Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Clause(head, body Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Close(streamOrAlias, options Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) CurrentCharConversion(inChar, outChar Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) CurrentInput(stream Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) CurrentOp(priority, specifier, op Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) CurrentOutput(stream Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) CurrentPredicate(pi Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) CurrentPrologFlag(flag, value Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Dynamic(pi Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Expand(term Term, env *Env) (Term, error)
- func (state *State) ExpandTerm(term1, term2 Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) FindAll(template, goal, instances Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) FlushOutput(streamOrAlias Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) GetByte(streamOrAlias, inByte Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) GetChar(streamOrAlias, char Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Negation(goal Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Op(priority, specifier, op Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Open(SourceSink, mode, stream, options Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Parser(r io.Reader, vars *[]ParsedVariable) *Parser
- func (state *State) PeekByte(streamOrAlias, inByte Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) PeekChar(streamOrAlias, char Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Phrase(grBody, s0, s Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) PutByte(streamOrAlias, byt Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) PutCode(streamOrAlias, code Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) ReadTerm(streamOrAlias, out, options Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Repeat(k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Retract(t Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) SetInput(streamOrAlias Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) SetOf(template, goal, instances Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) SetOutput(streamOrAlias Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) SetPrologFlag(flag, value Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) SetStreamPosition(streamOrAlias, position Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) SetUserInput(r io.Reader, opts ...StreamOption)
- func (state *State) SetUserOutput(w io.Writer, opts ...StreamOption)
- func (state *State) StreamProperty(streamOrAlias, property Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) Write(w io.Writer, t Term, opts *WriteOptions, env *Env) error
- func (state *State) WriteTerm(streamOrAlias, t, options Term, k func(*Env) *Promise, env *Env) *Promise
- type Stream
- type StreamMode
- type StreamOption
- type StreamType
- type Term
- func CharList(s string) Term
- func CodeList(s string) Term
- func Cons(car, cdr Term) Term
- func List(ts ...Term) Term
- func ListRest(rest Term, ts ...Term) Term
- func Pair(k, v Term) Term
- func Rulify(t Term, env *Env) Term
- func Seq(sep Atom, ts ...Term) Term
- func Slice(list Term, env *Env) ([]Term, error)
- type TermID
- type TermIDer
- type Token
- type TokenKind
- type VM
- func (vm *VM) Arrive(pi ProcedureIndicator, args []Term, k func(*Env) *Promise, env *Env) *Promise
- func (vm *VM) Register0(name string, p func(func(*Env) *Promise, *Env) *Promise)
- func (vm *VM) Register1(name string, p func(Term, func(*Env) *Promise, *Env) *Promise)
- func (vm *VM) Register2(name string, p func(Term, Term, func(*Env) *Promise, *Env) *Promise)
- func (vm *VM) Register3(name string, p func(Term, Term, Term, func(*Env) *Promise, *Env) *Promise)
- func (vm *VM) Register4(name string, ...)
- func (vm *VM) Register5(name string, ...)
- func (vm *VM) Register6(name string, ...)
- func (vm *VM) Register7(name string, ...)
- func (vm *VM) Register8(name string, ...)
- type ValidDomain
- type ValidType
- type Variable
- type WriteOptions
Constants ¶
const ( // StreamModeRead means you can read from the stream. StreamModeRead = StreamMode(os.O_RDONLY) // StreamModeWrite means you can write to the stream. StreamModeWrite = StreamMode(os.O_CREATE | os.O_WRONLY) // StreamModeAppend means you can append to the stream. StreamModeAppend = StreamMode(os.O_APPEND) | StreamModeWrite )
Variables ¶
var ( // Success is a continuation that leads to true. Success = func(*Env) *Promise { return Bool(true) } // Failure is a continuation that leads to false. Failure = func(*Env) *Promise { return Bool(false) } )
var DefaultEvaluableFunctors = EvaluableFunctors{ Constant: map[Atom]Number{ `pi`: Float(math.Pi), }, Unary: map[Atom]func(Number) (Number, error){ `-`: Neg, `abs`: Abs, `sign`: Sign, `float_integer_part`: FloatIntegerPart, `float_fractional_part`: FloatFractionalPart, `float`: AsFloat, `floor`: Floor, `truncate`: Truncate, `round`: Round, `ceiling`: Ceiling, `sin`: Sin, `cos`: Cos, `atan`: Atan, `exp`: Exp, `log`: Log, `sqrt`: Sqrt, `\`: BitwiseComplement, `+`: Pos, `asin`: Asin, `acos`: Acos, `tan`: Tan, }, Binary: map[Atom]func(Number, Number) (Number, error){ `+`: Add, `-`: Sub, `*`: Mul, `//`: IntDiv, `/`: Div, `rem`: Rem, `mod`: Mod, `**`: Power, `>>`: BitwiseRightShift, `<<`: BitwiseLeftShift, `/\`: BitwiseAnd, `\/`: BitwiseOr, `div`: IntFloorDiv, `max`: Max, `min`: Min, `^`: IntegerPower, `atan2`: Atan2, `xor`: Xor, }, }
DefaultEvaluableFunctors is a EvaluableFunctors with builtin functions.
var ( // ErrInsufficient is a parsing error which can be resolved by adding more characters to the input. ErrInsufficient = errors.New("insufficient") )
Functions ¶
Types ¶
type AltIterator ¶ added in v0.9.0
AltIterator is an iterator for alternatives.
func (*AltIterator) Current ¶ added in v0.9.0
func (i *AltIterator) Current() Term
Current returns the current element.
func (*AltIterator) Next ¶ added in v0.9.0
func (i *AltIterator) Next() bool
Next proceeds to the next element of the alternatives and returns true if there's such an element.
type AnyIterator ¶ added in v0.9.0
AnyIterator is an iterator for a list or a sequence.
func (*AnyIterator) Current ¶ added in v0.9.0
func (i *AnyIterator) Current() Term
Current returns the current element.
func (*AnyIterator) Next ¶ added in v0.9.0
func (i *AnyIterator) Next() bool
Next proceeds to the next element and returns true if there's such an element.
type EOFAction ¶ added in v0.4.1
type EOFAction int
EOFAction describes what happens when you reached to the end of the stream.
type Env ¶ added in v0.4.1
type Env struct {
// contains filtered or unexported fields
}
Env is a mapping from variables to terms.
var GoStringEnv *Env
GoStringEnv is an Env which resolves a Variable when GoString() is called.
func (*Env) FreeVariables ¶ added in v0.4.1
FreeVariables extracts variables in the given terms.
func (*Env) Resolve ¶ added in v0.4.1
Resolve follows the variable chain and returns the first non-variable term or the last free variable.
type EvaluableFunctors ¶ added in v0.9.0
type EvaluableFunctors struct { // Constant is a set of constants. Constant map[Atom]Number // Unary is a set of functions of arity 1. Unary map[Atom]func(x Number) (Number, error) // Binary is a set of functions of arity 2. Binary map[Atom]func(x, y Number) (Number, error) }
EvaluableFunctors is a set of unary/binary functions.
func (EvaluableFunctors) GreaterThan ¶ added in v0.9.0
GreaterThan succeeds iff e1 is greater than e2.
func (EvaluableFunctors) GreaterThanOrEqual ¶ added in v0.9.0
func (e EvaluableFunctors) GreaterThanOrEqual(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise
GreaterThanOrEqual succeeds iff e1 is greater than or equal to e2.
func (EvaluableFunctors) Is ¶ added in v0.9.0
Is evaluates expression and unifies the result with result.
func (EvaluableFunctors) LessThanOrEqual ¶ added in v0.9.0
LessThanOrEqual succeeds iff e1 is less than or equal to e2.
type Exception ¶
type Exception struct {
// contains filtered or unexported fields
}
Exception is an error represented by a prolog term.
func DomainError ¶ added in v0.4.0
func DomainError(validDomain ValidDomain, culprit Term, env *Env) Exception
DomainError creates a new domain error exception.
func EvaluationError ¶ added in v0.10.0
func EvaluationError(ev ExceptionalValue, env *Env) Exception
EvaluationError creates a new evaluation error exception.
func ExistenceError ¶ added in v0.4.0
func ExistenceError(objectType ObjectType, culprit Term, env *Env) Exception
ExistenceError creates a new existence error exception.
func InstantiationError ¶ added in v0.4.0
InstantiationError returns an instantiation error exception.
func NewException ¶ added in v0.10.0
NewException creates an exception from a copy of the given term.
func PermissionError ¶ added in v0.4.0
func PermissionError(operation Operation, permissionType PermissionType, culprit Term, env *Env) Exception
PermissionError creates a new permission error exception.
func RepresentationError ¶ added in v0.10.0
RepresentationError creates a new representation error exception.
func ResourceError ¶ added in v0.10.0
ResourceError creates a new resource error exception.
func SyntaxError ¶ added in v0.10.0
SyntaxError creates a new syntax error exception.
func SystemError ¶ added in v0.4.0
SystemError creates a new system error exception.
type ExceptionalValue ¶ added in v0.10.0
type ExceptionalValue uint8
ExceptionalValue is an evaluable functor's result which is not a number.
const ( ExceptionalValueFloatOverflow ExceptionalValue = iota ExceptionalValueIntOverflow ExceptionalValueUnderflow ExceptionalValueZeroDivisor ExceptionalValueUndefined )
ExceptionalValue is one of these values.
func (ExceptionalValue) Error ¶ added in v0.10.0
func (ev ExceptionalValue) Error() string
func (ExceptionalValue) Term ¶ added in v0.10.0
func (ev ExceptionalValue) Term() Term
Term returns an Atom for the ExceptionalValue.
type Flag ¶ added in v0.10.0
type Flag uint8
Flag is an implementation defined limit.
type Lexer ¶ added in v0.4.1
type Lexer struct {
// contains filtered or unexported fields
}
Lexer turns bytes into tokens.
type ListIterator ¶ added in v0.9.0
type ListIterator struct { List Term Env *Env AllowPartial bool // contains filtered or unexported fields }
ListIterator is an iterator for a list.
func (*ListIterator) Current ¶ added in v0.9.0
func (i *ListIterator) Current() Term
Current returns the current element.
func (*ListIterator) Next ¶ added in v0.9.0
func (i *ListIterator) Next() bool
Next proceeds to the next element of the list and returns true if there's such an element.
func (*ListIterator) Suffix ¶ added in v0.10.0
func (i *ListIterator) Suffix() Term
Suffix returns the rest of the list.
type Number ¶ added in v0.9.0
type Number interface { Term // contains filtered or unexported methods }
Number is a prolog number, either Integer or Float.
func BitwiseAnd ¶ added in v0.9.0
BitwiseAnd returns the logical AND on each bit.
func BitwiseComplement ¶ added in v0.9.0
BitwiseComplement returns the logical negation on each bit.
func BitwiseLeftShift ¶ added in v0.9.0
BitwiseLeftShift returns n bit-shifted by s to the left.
func BitwiseRightShift ¶ added in v0.9.0
BitwiseRightShift returns n bit-shifted by s to the right.
func FloatFractionalPart ¶ added in v0.9.0
FloatFractionalPart returns the fractional part of x.
func FloatIntegerPart ¶ added in v0.9.0
FloatIntegerPart returns the integer part of x.
func IntFloorDiv ¶ added in v0.9.0
IntFloorDiv returns the integer floor division.
func IntegerPower ¶ added in v0.9.0
IntegerPower returns x raised to the power of y.
type ObjectType ¶ added in v0.10.0
type ObjectType uint8
ObjectType is the object on which an operation is to be performed.
const ( ObjectTypeProcedure ObjectType = iota ObjectTypeSourceSink ObjectTypeStream )
ObjectType is one of these values.
func (ObjectType) Term ¶ added in v0.10.0
func (ot ObjectType) Term() Term
Term returns an Atom for the ObjectType.
type Operation ¶ added in v0.10.0
type Operation uint8
Operation is the operation to be performed.
type ParsedVariable ¶ added in v0.4.1
ParsedVariable is a set of information regarding a variable in a parsed term.
type Parser ¶ added in v0.4.1
type Parser struct {
// contains filtered or unexported fields
}
Parser turns bytes into Term.
type PermissionType ¶ added in v0.10.0
type PermissionType uint8
PermissionType is the type to which the operation is not permitted to perform.
const ( PermissionTypeBinaryStream PermissionType = iota PermissionTypeFlag PermissionTypeOperator PermissionTypePastEndOfStream PermissionTypePrivateProcedure PermissionTypeStaticProcedure PermissionTypeSourceSink PermissionTypeStream PermissionTypeTextStream )
PermissionType is one of these values.
func (PermissionType) Term ¶ added in v0.10.0
func (pt PermissionType) Term() Term
Term returns an Atom for the PermissionType.
type ProcedureIndicator ¶ added in v0.3.0
ProcedureIndicator identifies procedure e.g. (=)/2.
func NewProcedureIndicator ¶ added in v0.4.1
func NewProcedureIndicator(pi Term, env *Env) (ProcedureIndicator, error)
NewProcedureIndicator creates a new ProcedureIndicator from a term that matches Name/Arity.
func (ProcedureIndicator) Apply ¶ added in v0.3.0
func (p ProcedureIndicator) Apply(args ...Term) (Term, error)
Apply applies p to args.
func (ProcedureIndicator) String ¶ added in v0.3.0
func (p ProcedureIndicator) String() string
func (ProcedureIndicator) Term ¶ added in v0.3.0
func (p ProcedureIndicator) Term() Term
Term returns p as term.
type Promise ¶ added in v0.4.1
type Promise struct {
// contains filtered or unexported fields
}
Promise is a delayed execution that results in (bool, error). The zero value for Promise is equivalent to Bool(false).
func AcyclicTerm ¶ added in v0.9.0
AcyclicTerm checks if t is acyclic.
func Arg ¶
Arg extracts nth argument of term as arg, or finds the argument position of arg in term as nth.
func AtomChars ¶
AtomChars breaks down atom into list of characters and unifies with chars, or constructs an atom from a list of characters chars and unifies it with atom.
func AtomCodes ¶
AtomCodes breaks up atom into a list of runes and unifies it with codes, or constructs an atom from the list of runes and unifies it with atom.
func AtomConcat ¶
AtomConcat concatenates atom1 and atom2 and unifies it with atom3.
func AtomLength ¶
AtomLength counts the runes in atom and unifies the result with length.
func Between ¶ added in v0.9.0
Between succeeds when lower, upper, and value are all integers, and lower <= value <= upper. If value is a variable, it is unified with successive integers from lower to upper.
func Catch ¶ added in v0.4.1
Catch returns a promise with a recovering function. Once a promise results in error, the error goes through ancestor promises looking for a recovering function that returns a non-nil promise to continue on.
func Cut ¶ added in v0.4.1
Cut returns a promise that once the execution reaches it, it eliminates other possible choices.
func Functor ¶
Functor extracts the name and arity of term, or unifies term with an atomic/compound term of name and arity with fresh variables as arguments.
func KeySort ¶ added in v0.9.0
KeySort succeeds if sorted is a sorted list of pairs based on their keys.
func NumberChars ¶
NumberChars breaks up an atom representation of a number num into a list of characters and unifies it with chars, or constructs a number from a list of characters chars and unifies it with num.
func NumberCodes ¶
NumberCodes breaks up an atom representation of a number num into a list of runes and unifies it with codes, or constructs a number from a list of runes codes and unifies it with num.
func SkipMaxList ¶ added in v0.10.0
SkipMaxList iterates over list up to max elements and unifies the number of skipped elements with skip and the rest with suffix.
func SubAtom ¶
SubAtom unifies subAtom with a sub atom of length which appears with before runes preceding it and after runes following it.
func SubsumesTerm ¶ added in v0.9.0
SubsumesTerm succeeds if general and specific are unifiable without binding variables in specific.
func TermVariables ¶ added in v0.9.0
TermVariables succeeds if vars unifies with a list of variables in term.
func TypeCompound ¶
TypeCompound checks if t is a compound term.
func TypeInteger ¶
TypeInteger checks if t is an integer.
func UnifyWithOccursCheck ¶
UnifyWithOccursCheck unifies x and y with occurs check (i.e., X = f(X) is not allowed).
type Resource ¶ added in v0.10.0
type Resource uint8
Resource is a resource required to complete execution.
type SeqIterator ¶ added in v0.9.0
SeqIterator is an iterator for a sequence.
func (*SeqIterator) Current ¶ added in v0.9.0
func (i *SeqIterator) Current() Term
Current returns the current element.
func (*SeqIterator) Next ¶ added in v0.9.0
func (i *SeqIterator) Next() bool
Next proceeds to the next element of the sequence and returns true if there's such an element.
type State ¶ added in v0.5.0
type State struct { VM // contains filtered or unexported fields }
State represents the internal state of an interpreter.
func (*State) Abolish ¶ added in v0.5.0
Abolish removes the procedure indicated by pi from the database.
func (*State) BagOf ¶ added in v0.5.0
BagOf collects all the solutions of goal as instances, which unify with template. instances may contain duplications.
func (*State) BuiltIn ¶ added in v0.5.0
BuiltIn declares a procedure indicated by pi is built-in and static.
func (*State) Call ¶ added in v0.5.0
Call executes goal. it succeeds if goal followed by k succeeds. A cut inside goal doesn't affect outside of Call.
func (*State) Call1 ¶ added in v0.9.0
Call1 succeeds if closure with an additional argument succeeds.
func (*State) Call2 ¶ added in v0.9.0
Call2 succeeds if closure with 2 additional arguments succeeds.
func (*State) Call3 ¶ added in v0.9.0
Call3 succeeds if closure with 3 additional arguments succeeds.
func (*State) Call4 ¶ added in v0.9.0
func (state *State) Call4(closure, arg1, arg2, arg3, arg4 Term, k func(*Env) *Promise, env *Env) *Promise
Call4 succeeds if closure with 4 additional arguments succeeds.
func (*State) Call5 ¶ added in v0.9.0
func (state *State) Call5(closure, arg1, arg2, arg3, arg4, arg5 Term, k func(*Env) *Promise, env *Env) *Promise
Call5 succeeds if closure with 5 additional arguments succeeds.
func (*State) Call6 ¶ added in v0.9.0
func (state *State) Call6(closure, arg1, arg2, arg3, arg4, arg5, arg6 Term, k func(*Env) *Promise, env *Env) *Promise
Call6 succeeds if closure with 6 additional arguments succeeds.
func (*State) Call7 ¶ added in v0.9.0
func (state *State) Call7(closure, arg1, arg2, arg3, arg4, arg5, arg6, arg7 Term, k func(*Env) *Promise, env *Env) *Promise
Call7 succeeds if closure with 7 additional arguments succeeds.
func (*State) CallNth ¶ added in v0.10.0
CallNth succeeds iff goal succeeds and nth unifies with the number of re-execution. See http://www.complang.tuwien.ac.at/ulrich/iso-prolog/call_nth
func (*State) Catch ¶ added in v0.5.0
Catch calls goal. If an exception is thrown and unifies with catcher, it calls recover.
func (*State) CharConversion ¶ added in v0.5.0
CharConversion registers a character conversion from inChar to outChar, or remove the conversion if inChar = outChar.
func (*State) Clause ¶ added in v0.5.0
Clause unifies head and body with H and B respectively where H :- B is in the database.
func (*State) CurrentCharConversion ¶ added in v0.5.0
func (state *State) CurrentCharConversion(inChar, outChar Term, k func(*Env) *Promise, env *Env) *Promise
CurrentCharConversion succeeds iff a conversion from inChar to outChar is defined.
func (*State) CurrentInput ¶ added in v0.5.0
CurrentInput unifies stream with the current input stream.
func (*State) CurrentOp ¶ added in v0.5.0
func (state *State) CurrentOp(priority, specifier, op Term, k func(*Env) *Promise, env *Env) *Promise
CurrentOp succeeds if operator is defined with priority and specifier.
func (*State) CurrentOutput ¶ added in v0.5.0
CurrentOutput unifies stream with the current output stream.
func (*State) CurrentPredicate ¶ added in v0.5.0
CurrentPredicate matches pi with a predicate indicator of the user-defined procedures in the database.
func (*State) CurrentPrologFlag ¶ added in v0.5.0
CurrentPrologFlag succeeds iff flag is set to value.
func (*State) Dynamic ¶ added in v0.5.0
Dynamic declares a procedure indicated by pi is user-defined dynamic.
func (*State) Expand ¶ added in v0.9.0
Expand expands term according to term_expansion/2 and DCG rules.
func (*State) ExpandTerm ¶ added in v0.5.0
ExpandTerm transforms term1 according to term_expansion/2 and DCG rules then unifies with term2.
func (*State) FindAll ¶ added in v0.5.0
func (state *State) FindAll(template, goal, instances Term, k func(*Env) *Promise, env *Env) *Promise
FindAll collects all the solutions of goal as instances, which unify with template. instances may contain duplications.
func (*State) FlushOutput ¶ added in v0.5.0
FlushOutput sends any buffered output to the stream.
func (*State) GetByte ¶ added in v0.5.0
GetByte reads a byte from the stream represented by streamOrAlias and unifies it with inByte.
func (*State) GetChar ¶ added in v0.5.0
GetChar reads a character from the stream represented by streamOrAlias and unifies it with char.
func (*State) Negation ¶ added in v0.5.0
Negation calls goal and returns false if it succeeds. Otherwise, invokes the continuation.
func (*State) Op ¶ added in v0.5.0
Op defines operator with priority and specifier, or removes when priority is 0.
func (*State) Open ¶ added in v0.5.0
func (state *State) Open(SourceSink, mode, stream, options Term, k func(*Env) *Promise, env *Env) *Promise
Open opens SourceSink in mode and unifies with stream.
func (*State) Parser ¶ added in v0.5.0
func (state *State) Parser(r io.Reader, vars *[]ParsedVariable) *Parser
Parser creates a new parser from the current State and io.Reader. If non-nil, vars will hold the information on variables it parses.
func (*State) PeekByte ¶ added in v0.5.0
PeekByte peeks a byte from the stream represented by streamOrAlias and unifies it with inByte.
func (*State) PeekChar ¶ added in v0.5.0
PeekChar peeks a rune from the stream represented by streamOrAlias and unifies it with char.
func (*State) Phrase ¶ added in v0.9.0
Phrase succeeds if the difference list of s0-s satisfies the grammar rule of grBody.
func (*State) PutByte ¶ added in v0.5.0
PutByte outputs an integer byte to a stream represented by streamOrAlias.
func (*State) PutCode ¶ added in v0.5.0
PutCode outputs code to the stream represented by streamOrAlias.
func (*State) ReadTerm ¶ added in v0.5.0
func (state *State) ReadTerm(streamOrAlias, out, options Term, k func(*Env) *Promise, env *Env) *Promise
ReadTerm reads from the stream represented by streamOrAlias and unifies with stream.
func (*State) SetOf ¶ added in v0.5.0
SetOf collects all the solutions of goal as instances, which unify with template. instances don't contain duplications.
func (*State) SetOutput ¶ added in v0.5.0
SetOutput sets streamOrAlias as the current output stream.
func (*State) SetPrologFlag ¶ added in v0.5.0
SetPrologFlag sets flag to value.
func (*State) SetStreamPosition ¶ added in v0.5.0
func (state *State) SetStreamPosition(streamOrAlias, position Term, k func(*Env) *Promise, env *Env) *Promise
SetStreamPosition sets the position property of the stream represented by streamOrAlias.
func (*State) SetUserInput ¶ added in v0.5.0
func (state *State) SetUserInput(r io.Reader, opts ...StreamOption)
SetUserInput sets the given reader as a stream with an alias of user_input.
func (*State) SetUserOutput ¶ added in v0.5.0
func (state *State) SetUserOutput(w io.Writer, opts ...StreamOption)
SetUserOutput sets the given writer as a stream with an alias of user_output.
func (*State) StreamProperty ¶ added in v0.5.0
func (state *State) StreamProperty(streamOrAlias, property Term, k func(*Env) *Promise, env *Env) *Promise
StreamProperty succeeds iff the stream represented by streamOrAlias has the stream property.
type Stream ¶ added in v0.4.1
type Stream struct {
// contains filtered or unexported fields
}
Stream is a prolog stream.
func NewStream ¶ added in v0.4.1
func NewStream(f io.ReadWriteCloser, mode StreamMode, opts ...StreamOption) *Stream
NewStream creates a new stream from an opened file.
func Open ¶ added in v0.4.1
func Open(name Atom, mode StreamMode, opts ...StreamOption) (*Stream, error)
Open opens a file and creates a new stream out of it.
type StreamMode ¶ added in v0.4.1
type StreamMode int
StreamMode describes what operations you can perform on the stream.
func (StreamMode) String ¶ added in v0.6.0
func (m StreamMode) String() string
type StreamOption ¶ added in v0.4.1
type StreamOption func(*Stream)
StreamOption describes an option on stream creation.
func WithAlias ¶ added in v0.4.1
func WithAlias(state *State, alias Atom) StreamOption
WithAlias sets an alias for the stream.
func WithEOFAction ¶ added in v0.4.1
func WithEOFAction(eofAction EOFAction) StreamOption
WithEOFAction sets eof_action for the stream.
func WithReposition ¶ added in v0.4.1
func WithReposition(b bool) StreamOption
WithReposition sets if the stream is random access.
func WithStreamType ¶ added in v0.4.1
func WithStreamType(streamType StreamType) StreamOption
WithStreamType sets type of the stream.
type StreamType ¶ added in v0.4.1
type StreamType int
StreamType describes what will be transferred in the stream, either text or binary.
const ( // StreamTypeText means text. StreamTypeText StreamType = iota // StreamTypeBinary means binary. StreamTypeBinary )
func (StreamType) String ¶ added in v0.6.0
func (t StreamType) String() string
type Term ¶ added in v0.4.1
type Term interface { }
Term is a prolog term.
type TermIDer ¶ added in v0.11.0
type TermIDer interface {
TermID() TermID
}
TermIDer lets a Term which is not comparable per se return its TermID for comparison.
type TokenKind ¶ added in v0.4.1
type TokenKind byte
TokenKind is a type of Token.
const ( // TokenInvalid represents an invalid token. TokenInvalid TokenKind = iota // TokenInsufficient represents an insufficient token. TokenInsufficient // TokenEOF represents an end of token stream. TokenEOF // TokenLetterDigit represents a letter digit token. TokenLetterDigit // TokenGraphic represents a graphical token. TokenGraphic // TokenQuoted represents a quoted token. TokenQuoted // TokenSemicolon represents a semicolon token. TokenSemicolon // TokenCut represents a cut token. TokenCut // TokenVariable represents a variable token. TokenVariable // TokenInteger represents an integer token. TokenInteger // TokenFloatNumber represents a floating-point token. TokenFloatNumber // TokenDoubleQuotedList represents a double-quoted string. TokenDoubleQuotedList // TokenOpen represents an open parenthesis. TokenOpen // TokenOpenCT represents an open CT parenthesis. TokenOpenCT // TokenClose represents a close parenthesis. TokenClose // TokenOpenList represents an open bracket. TokenOpenList // TokenCloseList represents a close bracket. TokenCloseList // TokenOpenCurly represents an open brace. TokenOpenCurly // TokenCloseCurly represents a close brace. TokenCloseCurly // TokenBar represents a bar. TokenBar // TokenComma represents a comma. TokenComma // TokenEnd represents a period. TokenEnd )
type VM ¶
type VM struct { // OnCall is a callback that is triggered when the VM reaches to the predicate. OnCall func(pi ProcedureIndicator, args []Term, env *Env) // OnExit is a callback that is triggered when the predicate succeeds and the VM continues. OnExit func(pi ProcedureIndicator, args []Term, env *Env) // OnFail is a callback that is triggered when the predicate fails and the VM backtracks. OnFail func(pi ProcedureIndicator, args []Term, env *Env) // OnRedo is a callback that is triggered when the VM retries the predicate as a result of backtrack. OnRedo func(pi ProcedureIndicator, args []Term, env *Env) // OnUnknown is a callback that is triggered when the VM reaches to an unknown predicate and also current_prolog_flag(unknown, warning). OnUnknown func(pi ProcedureIndicator, args []Term, env *Env) // contains filtered or unexported fields }
VM is the core of a Prolog interpreter. The zero value for VM is a valid VM without any builtin predicates.
func (*VM) Register4 ¶
func (vm *VM) Register4(name string, p func(Term, Term, Term, Term, func(*Env) *Promise, *Env) *Promise)
Register4 registers a predicate of arity 4.
func (*VM) Register5 ¶
func (vm *VM) Register5(name string, p func(Term, Term, Term, Term, Term, func(*Env) *Promise, *Env) *Promise)
Register5 registers a predicate of arity 5.
func (*VM) Register6 ¶ added in v0.9.0
func (vm *VM) Register6(name string, p func(Term, Term, Term, Term, Term, Term, func(*Env) *Promise, *Env) *Promise)
Register6 registers a predicate of arity 6.
type ValidDomain ¶ added in v0.10.0
type ValidDomain uint8
ValidDomain is the domain which the procedure defines.
const ( ValidDomainCharacterCodeList ValidDomain = iota ValidDomainCloseOption ValidDomainFlagValue ValidDomainIOMode ValidDomainNonEmptyList ValidDomainNotLessThanZero ValidDomainOperatorPriority ValidDomainOperatorSpecifier ValidDomainPrologFlag ValidDomainReadOption ValidDomainSourceSink ValidDomainStream ValidDomainStreamOption ValidDomainStreamOrAlias ValidDomainStreamPosition ValidDomainStreamProperty ValidDomainWriteOption ValidDomainOrder )
ValidDomain is one of these values.
func (ValidDomain) Term ¶ added in v0.10.0
func (vd ValidDomain) Term() Term
Term returns an Atom for the ValidDomain.
type ValidType ¶ added in v0.10.0
type ValidType uint8
ValidType is the correct type for an argument or one of its components.
const ( ValidTypeAtom ValidType = iota ValidTypeAtomic ValidTypeByte ValidTypeCallable ValidTypeCharacter ValidTypeCompound ValidTypeEvaluable ValidTypeInByte ValidTypeInCharacter ValidTypeInteger ValidTypeList ValidTypeNumber ValidTypePredicateIndicator ValidTypePair ValidTypeFloat )
ValidType is one of these values.