engine

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2022 License: MIT Imports: 20 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Atom added in v0.4.1

type Atom uint64

Atom is a prolog atom.

func NewAtom added in v0.13.0

func NewAtom(name string) Atom

NewAtom interns the given string and returns an Atom.

func (Atom) Apply added in v0.4.1

func (a Atom) Apply(args ...Term) Term

Apply returns a Compound which Functor is the Atom and args are the arguments. If the arguments are empty, then returns itself.

func (Atom) GoString added in v0.13.0

func (a Atom) GoString() string

func (Atom) String added in v0.4.1

func (a Atom) String() string

type Compound added in v0.4.1

type Compound interface {
	Functor() Atom
	Arity() int
	Arg(n int) Term
}

Compound is a Prolog compound.

type Env added in v0.4.1

type Env struct {
	// contains filtered or unexported fields
}

Env is a mapping from variables to terms.

func NewEnv added in v0.4.1

func NewEnv() *Env

NewEnv creates an empty environment.

func (*Env) Resolve added in v0.4.1

func (e *Env) Resolve(t Term) Term

Resolve follows the variable chain and returns the first non-variable term or the last free variable.

func (*Env) Simplify added in v0.4.1

func (e *Env) Simplify(t Term) Term

Simplify trys to remove as many variables as possible from term t.

func (*Env) Unify added in v0.11.0

func (e *Env) Unify(x, y Term, occursCheck bool) (*Env, bool)

type Exception

type Exception struct {
	// contains filtered or unexported fields
}

Exception is an error represented by a prolog term.

func NewException added in v0.10.0

func NewException(term Term, env *Env) Exception

NewException creates an Exception from a copy of the given Term.

func (Exception) Error

func (e Exception) Error() string

func (Exception) Term

func (e Exception) Term() Term

Term returns the underlying Term of the Exception.

type Float added in v0.4.1

type Float float64

Float is a prolog floating-point number.

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 runes into tokens.

func (*Lexer) Token added in v0.9.0

func (l *Lexer) Token() (Token, error)

Token returns the next token.

type ListIterator added in v0.9.0

type ListIterator struct {
	List         Term
	Env          *Env
	AllowPartial bool
	AllowCycle   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) Err added in v0.9.0

func (i *ListIterator) Err() error

Err returns an error.

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.

type ParsedVariable added in v0.4.1

type ParsedVariable struct {
	Name     Atom
	Variable Variable
	Count    int
}

ParsedVariable is a set of information regarding a variable in a parsed term.

type Parser added in v0.4.1

type Parser struct {
	Vars []ParsedVariable
	// contains filtered or unexported fields
}

Parser turns bytes into Term.

func NewParser added in v0.4.1

func NewParser(vm *VM, r io.RuneReader) *Parser

NewParser creates a new parser from the current VM and io.RuneReader.

func (*Parser) More added in v0.4.1

func (p *Parser) More() bool

More checks if the parser has more tokens to read.

func (*Parser) SetPlaceholder added in v0.14.0

func (p *Parser) SetPlaceholder(placeholder Atom, args ...interface{}) error

SetPlaceholder registers placeholder and its arguments. Every occurrence of placeholder will be replaced by arguments. Mismatch of the number of occurrences of placeholder and the number of arguments raises an error.

func (*Parser) Term added in v0.4.1

func (p *Parser) Term() (Term, error)

Term parses a term followed by a full stop.

type Predicate0 added in v0.14.0

type Predicate0 func(*VM, func(*Env) *Promise, *Env) *Promise

Predicate0 is a predicate of arity 0.

type Predicate1 added in v0.14.0

type Predicate1 func(*VM, Term, func(*Env) *Promise, *Env) *Promise

Predicate1 is a predicate of arity 1.

type Predicate2 added in v0.14.0

type Predicate2 func(*VM, Term, Term, func(*Env) *Promise, *Env) *Promise

Predicate2 is a predicate of arity 2.

type Predicate3 added in v0.14.0

type Predicate3 func(*VM, Term, Term, Term, func(*Env) *Promise, *Env) *Promise

Predicate3 is a predicate of arity 3.

type Predicate4 added in v0.14.0

type Predicate4 func(*VM, Term, Term, Term, Term, func(*Env) *Promise, *Env) *Promise

Predicate4 is a predicate of arity 4.

type Predicate5 added in v0.14.0

type Predicate5 func(*VM, Term, Term, Term, Term, Term, func(*Env) *Promise, *Env) *Promise

Predicate5 is a predicate of arity 5.

type Predicate6 added in v0.14.0

type Predicate6 func(*VM, Term, Term, Term, Term, Term, Term, func(*Env) *Promise, *Env) *Promise

Predicate6 is a predicate of arity 6.

type Predicate7 added in v0.14.0

type Predicate7 func(*VM, Term, Term, Term, Term, Term, Term, Term, func(*Env) *Promise, *Env) *Promise

Predicate7 is a predicate of arity 7.

type Predicate8 added in v0.14.0

type Predicate8 func(*VM, Term, Term, Term, Term, Term, Term, Term, Term, func(*Env) *Promise, *Env) *Promise

Predicate8 is a predicate of arity 8.

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 Abolish added in v0.14.0

func Abolish(vm *VM, pi Term, k func(*Env) *Promise, env *Env) *Promise

Abolish removes the procedure indicated by pi from the database.

func AcyclicTerm added in v0.9.0

func AcyclicTerm(_ *VM, t Term, k func(*Env) *Promise, env *Env) *Promise

AcyclicTerm checks if t is acyclic.

func Append added in v0.11.0

func Append(vm *VM, xs, ys, zs Term, k func(*Env) *Promise, env *Env) *Promise

Append succeeds iff zs is the concatenation of lists xs and ys.

func Arg

func Arg(vm *VM, nth, t, arg Term, k func(*Env) *Promise, env *Env) *Promise

Arg extracts nth argument of term as arg, or finds the argument position of arg in term as nth.

func Asserta added in v0.14.0

func Asserta(vm *VM, t Term, k func(*Env) *Promise, env *Env) *Promise

Asserta prepends t to the database.

func Assertz added in v0.14.0

func Assertz(vm *VM, t Term, k func(*Env) *Promise, env *Env) *Promise

Assertz appends t to the database.

func AtomChars

func AtomChars(vm *VM, atom, chars Term, k func(*Env) *Promise, env *Env) *Promise

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

func AtomCodes(vm *VM, atom, codes Term, k func(*Env) *Promise, env *Env) *Promise

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

func AtomConcat(vm *VM, atom1, atom2, atom3 Term, k func(*Env) *Promise, env *Env) *Promise

AtomConcat concatenates atom1 and atom2 and unifies it with atom3.

func AtomLength

func AtomLength(vm *VM, atom, length Term, k func(*Env) *Promise, env *Env) *Promise

AtomLength counts the runes in atom and unifies the result with length.

func BagOf added in v0.14.0

func BagOf(vm *VM, template, goal, instances Term, k func(*Env) *Promise, env *Env) *Promise

BagOf collects all the solutions of goal as instances, which unify with template. instances may contain duplications.

func Between added in v0.9.0

func Between(vm *VM, lower, upper, value Term, k func(*Env) *Promise, env *Env) *Promise

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 Bool added in v0.4.1

func Bool(ok bool) *Promise

Bool returns a promise that simply returns (ok, nil).

func Call added in v0.14.0

func Call(vm *VM, goal Term, k func(*Env) *Promise, env *Env) *Promise

Call executes goal. it succeeds if goal followed by k succeeds. A cut inside goal doesn't affect outside of Call.

func Call1 added in v0.14.0

func Call1(vm *VM, closure, arg1 Term, k func(*Env) *Promise, env *Env) *Promise

Call1 succeeds if closure with an additional argument succeeds.

func Call2 added in v0.14.0

func Call2(vm *VM, closure, arg1, arg2 Term, k func(*Env) *Promise, env *Env) *Promise

Call2 succeeds if closure with 2 additional arguments succeeds.

func Call3 added in v0.14.0

func Call3(vm *VM, closure, arg1, arg2, arg3 Term, k func(*Env) *Promise, env *Env) *Promise

Call3 succeeds if closure with 3 additional arguments succeeds.

func Call4 added in v0.14.0

func Call4(vm *VM, closure, arg1, arg2, arg3, arg4 Term, k func(*Env) *Promise, env *Env) *Promise

Call4 succeeds if closure with 4 additional arguments succeeds.

func Call5 added in v0.14.0

func Call5(vm *VM, closure, arg1, arg2, arg3, arg4, arg5 Term, k func(*Env) *Promise, env *Env) *Promise

Call5 succeeds if closure with 5 additional arguments succeeds.

func Call6 added in v0.14.0

func Call6(vm *VM, 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 Call7 added in v0.14.0

func Call7(vm *VM, 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 CallNth added in v0.14.0

func CallNth(vm *VM, goal, nth Term, k func(*Env) *Promise, env *Env) *Promise

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 Catch added in v0.4.1

func Catch(vm *VM, goal, catcher, recover Term, k func(*Env) *Promise, env *Env) *Promise

Catch calls goal. If an exception is thrown and unifies with catcher, it calls recover.

func CharCode

func CharCode(vm *VM, char, code Term, k func(*Env) *Promise, env *Env) *Promise

CharCode converts a single-rune Atom char to an Integer code, or vice versa.

func CharConversion added in v0.14.0

func CharConversion(vm *VM, inChar, outChar Term, k func(*Env) *Promise, env *Env) *Promise

CharConversion registers a character conversion from inChar to outChar, or remove the conversion if inChar = outChar.

func Clause added in v0.14.0

func Clause(vm *VM, head, body Term, k func(*Env) *Promise, env *Env) *Promise

Clause unifies head and body with H and B respectively where H :- B is in the database.

func Close added in v0.14.0

func Close(vm *VM, streamOrAlias, options Term, k func(*Env) *Promise, env *Env) *Promise

Close closes a stream specified by streamOrAlias.

func Compare

func Compare(vm *VM, order, term1, term2 Term, k func(*Env) *Promise, env *Env) *Promise

Compare compares term1 and term2 and unifies order with <, =, or >.

func Consult added in v0.14.0

func Consult(vm *VM, files Term, k func(*Env) *Promise, env *Env) *Promise

Consult executes Prolog texts in files.

func CopyTerm

func CopyTerm(vm *VM, in, out Term, k func(*Env) *Promise, env *Env) *Promise

CopyTerm clones in as out.

func CurrentCharConversion added in v0.14.0

func CurrentCharConversion(vm *VM, inChar, outChar Term, k func(*Env) *Promise, env *Env) *Promise

CurrentCharConversion succeeds iff a conversion from inChar to outChar is defined.

func CurrentInput added in v0.14.0

func CurrentInput(vm *VM, stream Term, k func(*Env) *Promise, env *Env) *Promise

CurrentInput unifies stream with the current input stream.

func CurrentOp added in v0.14.0

func CurrentOp(vm *VM, priority, specifier, op Term, k func(*Env) *Promise, env *Env) *Promise

CurrentOp succeeds if operator is defined with priority and specifier.

func CurrentOutput added in v0.14.0

func CurrentOutput(vm *VM, stream Term, k func(*Env) *Promise, env *Env) *Promise

CurrentOutput unifies stream with the current output stream.

func CurrentPredicate added in v0.14.0

func CurrentPredicate(vm *VM, pi Term, k func(*Env) *Promise, env *Env) *Promise

CurrentPredicate matches pi with a predicate indicator of the user-defined procedures in the database.

func CurrentPrologFlag added in v0.14.0

func CurrentPrologFlag(vm *VM, flag, value Term, k func(*Env) *Promise, env *Env) *Promise

CurrentPrologFlag succeeds iff flag is set to value.

func Delay added in v0.4.1

func Delay(k ...func(context.Context) *Promise) *Promise

Delay delays an execution of k.

func Environ added in v0.7.0

func Environ(vm *VM, key, value Term, k func(*Env) *Promise, env *Env) *Promise

Environ succeeds if an environment variable key has value.

func Equal added in v0.14.0

func Equal(_ *VM, e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise

Equal succeeds iff e1 equals to e2.

func Error added in v0.4.1

func Error(err error) *Promise

Error returns a promise that simply returns (false, err).

func ExpandTerm added in v0.14.0

func ExpandTerm(vm *VM, term1, term2 Term, k func(*Env) *Promise, env *Env) *Promise

ExpandTerm transforms term1 according to term_expansion/2 and DCG rules then unifies with term2.

func Failure

func Failure(*Env) *Promise

Failure is a continuation that leads to false.

func FindAll added in v0.14.0

func FindAll(vm *VM, 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 FlushOutput added in v0.14.0

func FlushOutput(vm *VM, streamOrAlias Term, k func(*Env) *Promise, env *Env) *Promise

FlushOutput sends any buffered output to the stream.

func Functor

func Functor(vm *VM, t, name, arity Term, k func(*Env) *Promise, env *Env) *Promise

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 GetByte added in v0.14.0

func GetByte(vm *VM, streamOrAlias, inByte Term, k func(*Env) *Promise, env *Env) *Promise

GetByte reads a byte from the stream represented by streamOrAlias and unifies it with inByte.

func GetChar added in v0.14.0

func GetChar(vm *VM, streamOrAlias, char Term, k func(*Env) *Promise, env *Env) *Promise

GetChar reads a character from the stream represented by streamOrAlias and unifies it with char.

func GreaterThan added in v0.14.0

func GreaterThan(_ *VM, e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise

GreaterThan succeeds iff e1 is greater than e2.

func GreaterThanOrEqual added in v0.14.0

func GreaterThanOrEqual(_ *VM, e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise

GreaterThanOrEqual succeeds iff e1 is greater than or equal to e2.

func Halt added in v0.3.0

func Halt(_ *VM, n Term, k func(*Env) *Promise, env *Env) *Promise

Halt exits the process with exit code of n.

func Is added in v0.14.0

func Is(vm *VM, result, expression Term, k func(*Env) *Promise, env *Env) *Promise

Is evaluates expression and unifies the result with result.

func KeySort added in v0.9.0

func KeySort(vm *VM, pairs, sorted Term, k func(*Env) *Promise, env *Env) *Promise

KeySort succeeds if sorted is a sorted list of pairs based on their keys.

func Length added in v0.10.0

func Length(vm *VM, list, length Term, k func(*Env) *Promise, env *Env) *Promise

Length succeeds iff list is a list of length.

func LessThan added in v0.14.0

func LessThan(_ *VM, e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise

LessThan succeeds iff e1 is less than e2.

func LessThanOrEqual added in v0.14.0

func LessThanOrEqual(_ *VM, e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise

LessThanOrEqual succeeds iff e1 is less than or equal to e2.

func Negation added in v0.14.0

func Negation(vm *VM, goal Term, k func(*Env) *Promise, env *Env) *Promise

Negation calls goal and returns false if it succeeds. Otherwise, invokes the continuation.

func NotEqual added in v0.14.0

func NotEqual(_ *VM, e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise

NotEqual succeeds iff e1 doesn't equal to e2.

func Nth0 added in v0.9.0

func Nth0(vm *VM, n, list, elem Term, k func(*Env) *Promise, env *Env) *Promise

Nth0 succeeds if elem is the n-th element of list, counting from 0.

func Nth1 added in v0.9.0

func Nth1(vm *VM, n, list, elem Term, k func(*Env) *Promise, env *Env) *Promise

Nth1 succeeds if elem is the n-th element of list, counting from 1.

func NumberChars

func NumberChars(vm *VM, num, chars Term, k func(*Env) *Promise, env *Env) *Promise

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

func NumberCodes(vm *VM, num, codes Term, k func(*Env) *Promise, env *Env) *Promise

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 Op added in v0.14.0

func Op(vm *VM, priority, specifier, op Term, k func(*Env) *Promise, env *Env) *Promise

Op defines operator with priority and specifier, or removes when priority is 0.

func Open added in v0.4.1

func Open(vm *VM, sourceSink, mode, stream, options Term, k func(*Env) *Promise, env *Env) *Promise

Open opens SourceSink in mode and unifies with stream.

func PeekByte added in v0.14.0

func PeekByte(vm *VM, streamOrAlias, inByte Term, k func(*Env) *Promise, env *Env) *Promise

PeekByte peeks a byte from the stream represented by streamOrAlias and unifies it with inByte.

func PeekChar added in v0.14.0

func PeekChar(vm *VM, streamOrAlias, char Term, k func(*Env) *Promise, env *Env) *Promise

PeekChar peeks a rune from the stream represented by streamOrAlias and unifies it with char.

func Phrase added in v0.14.0

func Phrase(vm *VM, grBody, s0, s Term, k func(*Env) *Promise, env *Env) *Promise

Phrase succeeds if the difference list of s0-s satisfies the grammar rule of grBody.

func PutByte added in v0.14.0

func PutByte(vm *VM, streamOrAlias, byt Term, k func(*Env) *Promise, env *Env) *Promise

PutByte outputs an integer byte to a stream represented by streamOrAlias.

func PutCode added in v0.14.0

func PutCode(vm *VM, streamOrAlias, code Term, k func(*Env) *Promise, env *Env) *Promise

PutCode outputs code to the stream represented by streamOrAlias.

func ReadTerm added in v0.14.0

func ReadTerm(vm *VM, streamOrAlias, out, options Term, k func(*Env) *Promise, env *Env) *Promise

ReadTerm reads from the stream represented by streamOrAlias and unifies with stream.

func Repeat

func Repeat(_ *VM, k func(*Env) *Promise, env *Env) *Promise

Repeat repeats the continuation until it succeeds.

func Retract added in v0.14.0

func Retract(vm *VM, t Term, k func(*Env) *Promise, env *Env) *Promise

Retract removes the first clause that matches with t.

func SetInput added in v0.14.0

func SetInput(vm *VM, streamOrAlias Term, k func(*Env) *Promise, env *Env) *Promise

SetInput sets streamOrAlias as the current input stream.

func SetOf added in v0.14.0

func SetOf(vm *VM, template, goal, instances Term, k func(*Env) *Promise, env *Env) *Promise

SetOf collects all the solutions of goal as instances, which unify with template. instances don't contain duplications.

func SetOutput added in v0.14.0

func SetOutput(vm *VM, streamOrAlias Term, k func(*Env) *Promise, env *Env) *Promise

SetOutput sets streamOrAlias as the current output stream.

func SetPrologFlag added in v0.14.0

func SetPrologFlag(vm *VM, flag, value Term, k func(*Env) *Promise, env *Env) *Promise

SetPrologFlag sets flag to value.

func SetStreamPosition added in v0.14.0

func SetStreamPosition(vm *VM, streamOrAlias, position Term, k func(*Env) *Promise, env *Env) *Promise

SetStreamPosition sets the position property of the stream represented by streamOrAlias.

func SkipMaxList added in v0.10.0

func SkipMaxList(vm *VM, skip, max, list, suffix Term, k func(*Env) *Promise, env *Env) *Promise

SkipMaxList iterates over list up to max elements and unifies the number of skipped elements with skip and the rest with suffix.

func Sort added in v0.9.0

func Sort(vm *VM, list, sorted Term, k func(*Env) *Promise, env *Env) *Promise

Sort succeeds if sorted list of elements of list unifies with sorted.

func StreamProperty added in v0.14.0

func StreamProperty(vm *VM, stream, property Term, k func(*Env) *Promise, env *Env) *Promise

StreamProperty succeeds iff the stream represented by stream has the stream property.

func SubAtom

func SubAtom(vm *VM, atom, before, length, after, subAtom Term, k func(*Env) *Promise, env *Env) *Promise

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

func SubsumesTerm(_ *VM, general, specific Term, k func(*Env) *Promise, env *Env) *Promise

SubsumesTerm succeeds if general and specific are unifiable without binding variables in specific.

func Succ added in v0.9.0

func Succ(vm *VM, x, s Term, k func(*Env) *Promise, env *Env) *Promise

Succ succeeds if s is the successor of non-negative integer x.

func Success

func Success(*Env) *Promise

Success is a continuation that leads to true.

func TermVariables added in v0.9.0

func TermVariables(vm *VM, term, vars Term, k func(*Env) *Promise, env *Env) *Promise

TermVariables succeeds if vars unifies with a list of variables in term.

func Throw

func Throw(_ *VM, ball Term, _ func(*Env) *Promise, env *Env) *Promise

Throw throws ball as an exception.

func TypeAtom

func TypeAtom(_ *VM, t Term, k func(*Env) *Promise, env *Env) *Promise

TypeAtom checks if t is an atom.

func TypeCompound

func TypeCompound(_ *VM, t Term, k func(*Env) *Promise, env *Env) *Promise

TypeCompound checks if t is a compound term.

func TypeFloat

func TypeFloat(_ *VM, t Term, k func(*Env) *Promise, env *Env) *Promise

TypeFloat checks if t is a floating-point number.

func TypeInteger

func TypeInteger(_ *VM, t Term, k func(*Env) *Promise, env *Env) *Promise

TypeInteger checks if t is an integer.

func TypeVar

func TypeVar(_ *VM, t Term, k func(*Env) *Promise, env *Env) *Promise

TypeVar checks if t is a variable.

func Unify

func Unify(_ *VM, x, y Term, k func(*Env) *Promise, env *Env) *Promise

Unify unifies x and y without occurs check (i.e., X = f(X) is allowed).

func UnifyWithOccursCheck

func UnifyWithOccursCheck(_ *VM, x, y Term, k func(*Env) *Promise, env *Env) *Promise

UnifyWithOccursCheck unifies x and y with occurs check (i.e., X = f(X) is not allowed).

func Univ

func Univ(vm *VM, t, list Term, k func(*Env) *Promise, env *Env) *Promise

Univ constructs list as a list which first element is the functor of term and the rest is the arguments of term, or construct a compound from list as term.

func WriteTerm added in v0.11.0

func WriteTerm(vm *VM, streamOrAlias, t, options Term, k func(*Env) *Promise, env *Env) *Promise

WriteTerm outputs term to stream with options.

func (*Promise) Force added in v0.4.1

func (p *Promise) Force(ctx context.Context) (bool, error)

Force enforces the delayed execution and returns the result. (i.e. trampoline)

type Stream added in v0.4.1

type Stream struct {
	// contains filtered or unexported fields
}

Stream is a prolog stream.

func NewInputBinaryStream added in v0.14.0

func NewInputBinaryStream(r io.Reader) *Stream

NewInputBinaryStream creates a new input binary stream backed by the given io.Reader.

func NewInputTextStream added in v0.14.0

func NewInputTextStream(r io.Reader) *Stream

NewInputTextStream creates a new input text stream backed by the given io.Reader.

func NewOutputBinaryStream added in v0.14.0

func NewOutputBinaryStream(w io.Writer) *Stream

NewOutputBinaryStream creates a new output binary stream backed by the given io.Writer.

func NewOutputTextStream added in v0.14.0

func NewOutputTextStream(w io.Writer) *Stream

NewOutputTextStream creates a new output text stream backed by the given io.Writer.

func (*Stream) Close added in v0.4.1

func (s *Stream) Close() error

Close closes the underlying source/sink.

func (*Stream) Flush added in v0.14.0

func (s *Stream) Flush() error

Flush flushes the buffered output to the sink.

func (*Stream) Name added in v0.14.0

func (s *Stream) Name() string

Name returns the stream's name. If the underlying source/sink doesn't have a name, returns "".

func (*Stream) ReadByte added in v0.14.0

func (s *Stream) ReadByte() (byte, error)

ReadByte reads a byte from the underlying source. It throws an error if the stream is not an input binary stream.

func (*Stream) ReadRune added in v0.14.0

func (s *Stream) ReadRune() (r rune, size int, err error)

ReadRune reads the next rune from the underlying source. It throws an error if the stream is not an input text stream.

func (*Stream) Seek added in v0.14.0

func (s *Stream) Seek(offset int64, whence int) (int64, error)

Seek sets the offset to the underlying source/sink.

func (*Stream) UnreadByte added in v0.14.0

func (s *Stream) UnreadByte() error

func (*Stream) UnreadRune added in v0.14.0

func (s *Stream) UnreadRune() error

func (*Stream) Write added in v0.14.0

func (s *Stream) Write(p []byte) (int, error)

Write writes the contents of p to the underlying sink. It throws an error if the stream is not an output binary stream.

func (*Stream) WriteByte added in v0.14.0

func (s *Stream) WriteByte(c byte) error

WriteByte writes the byte c to the underlying sink. It throws an error if the stream is not an output binary stream,.

func (*Stream) WriteRune added in v0.14.0

func (s *Stream) WriteRune(r rune) (size int, err error)

WriteRune writes the rune r to the underlying sink. It throws an error if the stream is not an output binary stream.

func (*Stream) WriteString added in v0.14.0

func (s *Stream) WriteString(str string) (int, error)

WriteString writes the contents of str to the underlying sink. It throws an error if the stream is not an output text stream.

type Term added in v0.4.1

type Term interface {
}

Term is a prolog term.

func CharList added in v0.11.0

func CharList(s string) Term

CharList returns a character list.

func CodeList added in v0.11.0

func CodeList(s string) Term

CodeList returns a character code list.

func Cons added in v0.4.1

func Cons(car, cdr Term) Term

Cons returns a list consists of a first element car and the rest cdr.

func List added in v0.4.1

func List(ts ...Term) Term

List returns a list of ts.

func PartialList added in v0.14.0

func PartialList(tail Term, ts ...Term) Term

PartialList returns a list of ts followed by tail.

type Token added in v0.4.1

type Token struct {
	// contains filtered or unexported fields
}

Token is a smallest meaningful unit of prolog program.

func (Token) String added in v0.4.1

func (t Token) String() string

type VM

type VM struct {
	// Unknown is a callback that is triggered when the VM reaches to an unknown predicate while current_prolog_flag(unknown, warning).
	Unknown func(name Atom, args []Term, env *Env)

	// FS is a file system that is referenced when the VM loads Prolog texts e.g. ensure_loaded/1.
	// It has no effect on open/4 nor open/3 which always access the actual file system.
	FS fs.FS
	// 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) Arrive added in v0.5.0

func (vm *VM) Arrive(name Atom, args []Term, k func(*Env) *Promise, env *Env) *Promise

Arrive is the entry point of the VM.

func (*VM) Compile added in v0.14.0

func (vm *VM) Compile(ctx context.Context, s string, args ...interface{}) error

Compile compiles the Prolog text and updates the DB accordingly.

func (*VM) Register0

func (vm *VM) Register0(name Atom, p Predicate0)

Register0 registers a predicate of arity 0.

func (*VM) Register1

func (vm *VM) Register1(name Atom, p Predicate1)

Register1 registers a predicate of arity 1.

func (*VM) Register2

func (vm *VM) Register2(name Atom, p Predicate2)

Register2 registers a predicate of arity 2.

func (*VM) Register3

func (vm *VM) Register3(name Atom, p Predicate3)

Register3 registers a predicate of arity 3.

func (*VM) Register4

func (vm *VM) Register4(name Atom, p Predicate4)

Register4 registers a predicate of arity 4.

func (*VM) Register5

func (vm *VM) Register5(name Atom, p Predicate5)

Register5 registers a predicate of arity 5.

func (*VM) Register6 added in v0.9.0

func (vm *VM) Register6(name Atom, p Predicate6)

Register6 registers a predicate of arity 6.

func (*VM) Register7 added in v0.9.0

func (vm *VM) Register7(name Atom, p Predicate7)

Register7 registers a predicate of arity 7.

func (*VM) Register8 added in v0.9.0

func (vm *VM) Register8(name Atom, p Predicate8)

Register8 registers a predicate of arity 8.

func (*VM) SetUserInput

func (vm *VM) SetUserInput(s *Stream)

SetUserInput sets the given stream as user_input.

func (*VM) SetUserOutput

func (vm *VM) SetUserOutput(s *Stream)

SetUserOutput sets the given stream as user_output.

type Variable added in v0.4.1

type Variable int64

Variable is a prolog variable.

func NewVariable added in v0.4.1

func NewVariable() Variable

NewVariable creates a new anonymous variable.

func (Variable) String added in v0.4.1

func (v Variable) String() string

Jump to

Keyboard shortcuts

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