Documentation ¶
Index ¶
- Constants
- Variables
- func Contains(t, s Term, env *Env) bool
- func Each(any Term, f func(elem Term) error, env *Env) error
- func EachList(list Term, f func(elem Term) error, env *Env) error
- func EachSeq(seq Term, sep Atom, f func(elem Term) error, env *Env) error
- func Write(w io.Writer, t Term, opts WriteTermOptions, env *Env) error
- type Atom
- type Compound
- type DoubleQuotes
- type EOFAction
- type Env
- type Exception
- func DomainError(validDomain Atom, culprit Term, format string, args ...interface{}) *Exception
- func ExistenceError(objectType Atom, culprit Term, format string, args ...interface{}) *Exception
- func InstantiationError(culprit Term) *Exception
- func PermissionError(operation, permissionType Atom, culprit Term, format string, ...) *Exception
- func SystemError(err error) *Exception
- func TypeError(validType Atom, culprit Term, format string, args ...interface{}) *Exception
- type Float
- type FunctionSet
- func (fs FunctionSet) Equal(lhs, rhs Term, k func(*Env) *Promise, env *Env) *Promise
- func (fs FunctionSet) GreaterThan(lhs, rhs Term, k func(*Env) *Promise, env *Env) *Promise
- func (fs FunctionSet) GreaterThanOrEqual(lhs, rhs Term, k func(*Env) *Promise, env *Env) *Promise
- func (fs FunctionSet) Is(result, expression Term, k func(*Env) *Promise, env *Env) *Promise
- func (fs FunctionSet) LessThan(lhs, rhs Term, k func(*Env) *Promise, env *Env) *Promise
- func (fs FunctionSet) LessThanOrEqual(lhs, rhs Term, k func(*Env) *Promise, env *Env) *Promise
- func (fs FunctionSet) NotEqual(lhs, rhs Term, k func(*Env) *Promise, env *Env) *Promise
- type Integer
- type Lexer
- type Operator
- type OperatorSpecifier
- type Operators
- type ParsedVariable
- type Parser
- type ParserOption
- type ProcedureIndicator
- type 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 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 Error(err error) *Promise
- func Failure(_ *Env) *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 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 SubAtom(atom, before, length, after, subAtom Term, k func(*Env) *Promise, env *Env) *Promise
- func Success(_ *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(t1, t2 Term, k func(*Env) *Promise, env *Env) *Promise
- func UnifyWithOccursCheck(t1, t2 Term, k func(*Env) *Promise, env *Env) *Promise
- func Univ(t, list Term, k func(*Env) *Promise, env *Env) *Promise
- type State
- func (state *State) Abolish(pi Term, k func(*Env) *Promise, env *Env) *Promise
- func (state *State) AssertStatic(t Term, k func(*Env) *Promise, env *Env) *Promise
- 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) 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, operator 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) 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, operator 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) 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) WriteTerm(streamOrAlias, t, options Term, k func(*Env) *Promise, env *Env) *Promise
- type Stream
- type StreamMode
- type StreamOption
- type StreamType
- type Term
- type Token
- type TokenKind
- type UnexpectedRuneError
- type UnexpectedTokenError
- 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, ...)
- type Variable
- type Variables
- type WriteTermOptions
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 DefaultFunctionSet = FunctionSet{ Unary: map[Atom]func(Term, *Env) (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, *Env) (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 }), }, }
DefaultFunctionSet is a FunctionSet with builtin functions.
var ErrInsufficient = errors.New("insufficient input")
ErrInsufficient represents an error which is raised when the given input is insufficient for a term.
var ErrNotANumber = errors.New("not a number")
Functions ¶
Types ¶
type Atom ¶ added in v0.4.1
type Atom string
Atom is a prolog atom.
func (Atom) Apply ¶ added in v0.4.1
Apply returns a Compound which Functor is the Atom and Args are the arguments. If the arguments are empty, then returns itself.
type Compound ¶ added in v0.4.1
Compound is a prolog compound.
type DoubleQuotes ¶ added in v0.4.1
type DoubleQuotes int
const ( DoubleQuotesCodes DoubleQuotes = iota DoubleQuotesChars DoubleQuotesAtom )
func (DoubleQuotes) String ¶ added in v0.4.1
func (d DoubleQuotes) String() string
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.
func (*Env) FreeVariables ¶ added in v0.4.1
FreeVariables extracts variables in the given terms.
type Exception ¶
type Exception struct {
Term Term
}
Exception is an error represented by a prolog term.
func DomainError ¶ added in v0.4.0
DomainError creates a new domain error exception.
func ExistenceError ¶ added in v0.4.0
ExistenceError creates a new existence error exception.
func InstantiationError ¶ added in v0.4.0
InstantiationError creates a new instantiation error excdption.
func PermissionError ¶ added in v0.4.0
func PermissionError(operation, permissionType Atom, culprit Term, format string, args ...interface{}) *Exception
PermissionError creates a new permission error exception.
func SystemError ¶ added in v0.4.0
type Float ¶ added in v0.4.1
type Float float64
Float is a prolog floating-point number.
type FunctionSet ¶
type FunctionSet struct { Unary map[Atom]func(x Term, env *Env) (Term, error) Binary map[Atom]func(x, y Term, env *Env) (Term, error) }
FunctionSet is a set of unary/binary functions.
func (FunctionSet) GreaterThan ¶
GreaterThan succeeds iff lhs is greater than rhs.
func (FunctionSet) GreaterThanOrEqual ¶
GreaterThanOrEqual succeeds iff lhs is greater than or equal to rhs.
func (FunctionSet) LessThanOrEqual ¶
LessThanOrEqual succeeds iff lhs is less than or equal to rhs.
type Integer ¶ added in v0.4.1
type Integer int64
Integer is a prolog integer.
type Lexer ¶ added in v0.4.1
type Lexer struct {
// contains filtered or unexported fields
}
Lexer turns bytes into tokens.
type Operator ¶ added in v0.4.1
type Operator struct { Priority Integer // 1 ~ 1200 Specifier OperatorSpecifier Name Atom }
Operator is an operator definition.
type OperatorSpecifier ¶ added in v0.4.1
type OperatorSpecifier uint8
const ( OperatorSpecifierNone OperatorSpecifier = iota OperatorSpecifierFX OperatorSpecifierFY OperatorSpecifierXF OperatorSpecifierYF OperatorSpecifierXFX OperatorSpecifierXFY OperatorSpecifierYFX )
func (OperatorSpecifier) Term ¶ added in v0.4.1
func (s OperatorSpecifier) Term() Term
type Operators ¶ added in v0.4.1
type Operators []Operator
Operators are a list of operators sorted in a descending order of precedence.
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 ParserOption ¶ added in v0.4.1
type ParserOption func(p *Parser)
ParserOption is option for NewParser.
func WithDoubleQuotes ¶ added in v0.4.1
func WithDoubleQuotes(quotes DoubleQuotes) ParserOption
WithDoubleQuotes sets how Parser handles double quotes.
func WithOperators ¶ added in v0.4.1
func WithOperators(operators *Operators) ParserOption
WithOperators sets operators for Parser.
func WithParsedVars ¶ added in v0.4.1
func WithParsedVars(vars *[]ParsedVariable) ParserOption
WithParsedVars sets where Parser to store information regarding parsed variables.
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 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 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 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 SubAtom ¶
SubAtom unifies subAtom with a sub atom of atom of length which appears with before runes preceding it and after runes following it.
func TypeCompound ¶
TypeCompound checks if t is a compound term.
func TypeInteger ¶
TypeInteger checks if t is an integer.
func UnifyWithOccursCheck ¶
UnifyWithOccursCheck unifies t1 and t2 with occurs check (i.e., X = f(X) is not allowed).
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) AssertStatic ¶ added in v0.5.0
AssertStatic prepends t to 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) 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, operator 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) ExpandTerm ¶ added in v0.5.0
ExpandTerm transforms term1 according to term_expansion/2 and 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) Op ¶ added in v0.5.0
func (state *State) Op(priority, specifier, operator Term, k func(*Env) *Promise, env *Env) *Promise
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
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) 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.
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.
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 )
type Term ¶ added in v0.4.1
type Term interface { fmt.Stringer Unify(Term, bool, *Env) (*Env, bool) Unparse(func(Token), WriteTermOptions, *Env) }
Term is a prolog term.
type TokenKind ¶ added in v0.4.1
type TokenKind byte
TokenKind is a type of Token.
const ( // TokenEOS represents an end of token stream. TokenEOS TokenKind = iota // TokenVariable represents a variable token. TokenVariable // TokenFloat represents a floating-point token. TokenFloat // TokenInteger represents an integer token. TokenInteger // TokenIdent represents an identifier token. TokenIdent // TokenQuotedIdent represents a quoted identifier token. TokenQuotedIdent // TokenGraphic represents a graphical token. TokenGraphic // TokenComma represents a comma. TokenComma // TokenPeriod represents a period. TokenPeriod // TokenBar represents a bar. TokenBar // TokenParenL represents an open parenthesis. TokenParenL // TokenParenR represents a close parenthesis. TokenParenR // TokenBracketL represents an open bracket. TokenBracketL // TokenBracketR represents a close bracket. TokenBracketR // TokenBraceL represents an open brace. TokenBraceL // TokenBraceR represents a close brace. TokenBraceR // TokenSign represents a plus/minus. TokenSign // TokenDoubleQuoted represents a double-quoted string. TokenDoubleQuoted )
type UnexpectedRuneError ¶ added in v0.4.1
type UnexpectedRuneError struct {
// contains filtered or unexported fields
}
UnexpectedRuneError represents an error which is raised when the given input contains an unexpected rune.
func (UnexpectedRuneError) Error ¶ added in v0.4.1
func (e UnexpectedRuneError) Error() string
type UnexpectedTokenError ¶ added in v0.4.1
type UnexpectedTokenError struct { ExpectedKind TokenKind ExpectedVals []string Actual Token History []Token }
func (UnexpectedTokenError) Error ¶ added in v0.4.1
func (e UnexpectedTokenError) Error() string
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.
type Variable ¶ added in v0.4.1
type Variable string
Variable is a prolog variable.
func NewVariable ¶ added in v0.4.1
func NewVariable() Variable