term

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultWriteTermOptions = WriteTermOptions{
	Quoted: true,
	Ops: Operators{
		{Priority: 400, Specifier: "yfx", Name: "/"},
	},
	NumberVars: false,
}
View Source
var ErrNotANumber = errors.New("not a number")

Functions

func Compare

func Compare(a, b Interface) int64

func Contains

func Contains(t, s Interface, env *Env) bool

Contains checks if t contains s.

Types

type Atom

type Atom string

Atom is a prolog atom.

func (Atom) String

func (a Atom) String() string

func (Atom) Unify

func (a Atom) Unify(t Interface, occursCheck bool, env *Env) bool

Unify unifies the atom with t.

func (Atom) WriteTerm

func (a Atom) WriteTerm(w io.Writer, opts WriteTermOptions, _ Env) error

WriteTerm writes the atom into w.

type Binding

type Binding struct {
	Variable Variable
	Value    Interface
}

type Compound

type Compound struct {
	Functor Atom
	Args    []Interface
}

Compound is a prolog compound.

func (*Compound) String

func (c *Compound) String() string

func (*Compound) Unify

func (c *Compound) Unify(t Interface, occursCheck bool, env *Env) bool

Unify unifies the compound with t.

func (*Compound) WriteTerm

func (c *Compound) WriteTerm(w io.Writer, opts WriteTermOptions, env Env) error

WriteTerm writes the compound into w.

type Env

type Env []Binding

Env is an environment stack.

func (Env) FreeVariables

func (e Env) FreeVariables(ts ...Interface) []Variable

FreeVariables extracts variables in the given terms.

func (Env) Lookup

func (e Env) Lookup(v Variable) (Interface, bool)

func (Env) Resolve

func (e Env) Resolve(t Interface) Interface

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

func (Env) Simplify

func (e Env) Simplify(t Interface) Interface

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

type EofAction

type EofAction int
const (
	EofActionEOFCode EofAction = iota
	EofActionError
	EofActionReset
)

type Float

type Float float64

Float is a prolog floating-point number.

func (Float) String

func (f Float) String() string

func (Float) Unify

func (f Float) Unify(t Interface, occursCheck bool, env *Env) bool

Unify unifies the float with t.

func (Float) WriteTerm

func (f Float) WriteTerm(w io.Writer, _ WriteTermOptions, _ Env) error

WriteTerm writes the float into w.

type Integer

type Integer int64

Integer is a prolog integer.

func (Integer) String

func (i Integer) String() string

func (Integer) Unify

func (i Integer) Unify(t Interface, occursCheck bool, env *Env) bool

Unify unifies the integer with t.

func (Integer) WriteTerm

func (i Integer) WriteTerm(w io.Writer, _ WriteTermOptions, _ Env) error

WriteTerm writes the integer into w.

type Interface

type Interface interface {
	fmt.Stringer
	WriteTerm(io.Writer, WriteTermOptions, Env) error
	Unify(Interface, bool, *Env) bool
}

Interface is a prolog term.

func Cons

func Cons(car, cdr Interface) Interface

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

func List

func List(ts ...Interface) Interface

List returns a list of ts.

func ListRest

func ListRest(rest Interface, ts ...Interface) Interface

ListRest returns a list of ts followed by rest.

func Rulify

func Rulify(t Interface, env Env) Interface

Rulify returns t if t is in a form of P:-Q, t:-true otherwise.

func Set

func Set(ts ...Interface) Interface

Set returns a list of ts which elements are unique.

type Operator

type Operator struct {
	Priority  Integer // 1 ~ 1200
	Specifier Atom    // xf, yf, xfx, xfy, yfx, fx, or fy
	Name      Atom
}

Operator is an operator definition.

type Operators

type Operators []Operator

Operators are a list of operators sorted in a descending order of precedence.

type Parser

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

Parser turns bytes into Interface.

func NewParser

func NewParser(input *bufio.Reader, operators *Operators, charConversions map[rune]rune) *Parser

NewParser creates a Parser.

func (*Parser) More

func (p *Parser) More() bool

More checks if the parser has more tokens to read.

func (*Parser) Number

func (p *Parser) Number() (Interface, error)

Number parses a number term.

func (*Parser) Replace

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

Replace 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

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

Term parses a term followed by a full stop.

type Stream

type Stream struct {
	Source io.Reader
	Sink   io.Writer
	Closer io.Closer

	Mode       StreamMode
	Alias      Atom
	EofAction  EofAction
	Reposition bool
	StreamType StreamType
}

Stream is a prolog stream.

func (*Stream) String

func (s *Stream) String() string

func (*Stream) Unify

func (s *Stream) Unify(t Interface, occursCheck bool, env *Env) bool

Unify unifies the stream with t.

func (*Stream) WriteTerm

func (s *Stream) WriteTerm(w io.Writer, _ WriteTermOptions, _ Env) error

WriteTerm writes the stream into w.

type StreamMode

type StreamMode int
const (
	StreamModeRead StreamMode = iota
	StreamModeWrite
	StreamModeAppend
)

type StreamType

type StreamType int
const (
	StreamTypeText StreamType = iota
	StreamTypeBinary
)

type Variable

type Variable string

Variable is a prolog variable.

func NewVariable

func NewVariable() Variable

func (Variable) Anonymous

func (v Variable) Anonymous() bool

func (Variable) String

func (v Variable) String() string

func (Variable) Unify

func (v Variable) Unify(t Interface, occursCheck bool, env *Env) bool

Unify unifies the variable with t.

func (Variable) WriteTerm

func (v Variable) WriteTerm(w io.Writer, opts WriteTermOptions, env Env) error

WriteTerm writes the variable into w.

type VariableWithCount

type VariableWithCount struct {
	Variable Variable
	Count    int
}

type WriteTermOptions

type WriteTermOptions struct {
	Quoted      bool
	Ops         Operators
	NumberVars  bool
	Descriptive bool
}

WriteTermOptions describes options to write terms.

Jump to

Keyboard shortcuts

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