ivy: robpike.io/ivy/value Index | Files

package value

import "robpike.io/ivy/value"

Index

Package Files

asin.go bigfloat.go bigint.go bigrat.go binary.go char.go const.go context.go eval.go int.go log.go loop.go matrix.go power.go sin.go sqrt.go unary.go value.go vector.go

Variables

var BinaryOps = make(map[string]BinaryOp)
var IvyEval func(context Context, s string) Value

Implemented in main, handled as a func to avoid a dependency loop.

var (
    MaxBigInt63 = big.NewInt(int64(^uint64(0) >> 1))
)
var UnaryOps = make(map[string]UnaryOp)

func Consts Uses

func Consts(c Context) (e, pi BigFloat)

func Errorf Uses

func Errorf(format string, args ...interface{})

Errorf panics with the formatted string, with type Error.

func ParseString Uses

func ParseString(s string) string

ParseString parses a string. Single quotes and double quotes are both allowed (but must be consistent.) The result must contain only valid Unicode code points.

type BigFloat Uses

type BigFloat struct {
    *big.Float
}

func (BigFloat) Eval Uses

func (f BigFloat) Eval(Context) Value

func (BigFloat) Format Uses

func (i BigFloat) Format()

The fmt package looks for Formatter before Stringer, but we want to use Stringer only. big.Float implements Formatter, and we embed it in our BigFloat type. To make sure that our String gets called rather than the inner Format, we put a non-matching stub Format method into this interface. This is ugly but very simple and cheap.

func (BigFloat) Inner Uses

func (f BigFloat) Inner() Value

func (BigFloat) ProgString Uses

func (f BigFloat) ProgString() string

func (BigFloat) Sprint Uses

func (f BigFloat) Sprint(conf *config.Config) string

func (BigFloat) String Uses

func (f BigFloat) String() string

type BigInt Uses

type BigInt struct {
    *big.Int
}

func (BigInt) BitLen Uses

func (i BigInt) BitLen() int64

func (BigInt) Eval Uses

func (i BigInt) Eval(Context) Value

func (BigInt) Format Uses

func (i BigInt) Format()

The fmt package looks for Formatter before Stringer, but we want to use Stringer only. big.Int and big.Rat implement Formatter, and we embed them in our BigInt and BigRat types. To make sure that our String gets called rather than the inner Format, we put a non-matching stub Format method into this interface. This is ugly but very simple and cheap.

func (BigInt) Inner Uses

func (i BigInt) Inner() Value

func (BigInt) ProgString Uses

func (i BigInt) ProgString() string

func (BigInt) Sprint Uses

func (i BigInt) Sprint(conf *config.Config) string

func (BigInt) String Uses

func (i BigInt) String() string

type BigRat Uses

type BigRat struct {
    *big.Rat
}

func (BigRat) Eval Uses

func (r BigRat) Eval(Context) Value

func (BigRat) Inner Uses

func (r BigRat) Inner() Value

func (BigRat) ProgString Uses

func (r BigRat) ProgString() string

func (BigRat) Sprint Uses

func (r BigRat) Sprint(conf *config.Config) string

func (BigRat) String Uses

func (r BigRat) String() string

type BinaryOp Uses

type BinaryOp interface {
    EvalBinary(c Context, right, left Value) Value
}

BinaryOp is the interface implemented by a simple binary operator.

type Char Uses

type Char rune

func (Char) Eval Uses

func (c Char) Eval(Context) Value

func (Char) Inner Uses

func (c Char) Inner() Value

func (Char) ProgString Uses

func (c Char) ProgString() string

func (Char) Sprint Uses

func (c Char) Sprint(conf *config.Config) string

func (Char) String Uses

func (c Char) String() string

type Context Uses

type Context interface {
    // Lookup returns the configuration state for evaluation.
    Config() *config.Config

    // Lookup returns the value of a symbol.
    Lookup(name string) Value

    // Assign assigns the variable the value. The variable must
    // be defined either in the current function or globally.
    // Inside a function, new variables become locals.
    Assign(name string, value Value)

    // Eval evaluates a list of expressions.
    Eval(exprs []Expr) []Value

    // EvalUnaryFn evaluates a unary operator.
    EvalUnary(op string, right Value) Value

    // EvalBinary evaluates a binary operator.
    EvalBinary(left Value, op string, right Value) Value

    // UserDefined reports whether the specified op is user-defined.
    UserDefined(op string, isBinary bool) bool
}

Context is the execution context for evaluation. The only implementation is ../exec/Context, but the interface is defined separately, here, because of the dependence on Expr and the import cycle that would otherwise result.

type Error Uses

type Error string

Error is the type we recognize as a recoverable run-time error.

func (Error) Error Uses

func (err Error) Error() string

type Expr Uses

type Expr interface {
    // ProgString returns the unambiguous representation of the
    // expression to be used in program source.
    ProgString() string

    Eval(Context) Value
}

Expr is the interface for a parsed expression.

type Int Uses

type Int int64

func (Int) Eval Uses

func (i Int) Eval(Context) Value

func (Int) Inner Uses

func (i Int) Inner() Value

func (Int) ProgString Uses

func (i Int) ProgString() string

func (Int) Sprint Uses

func (i Int) Sprint(conf *config.Config) string

func (Int) String Uses

func (i Int) String() string

func (Int) ToBool Uses

func (i Int) ToBool() bool

type Matrix Uses

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

func NewMatrix Uses

func NewMatrix(shape, data []Value) Matrix

NewMatrix makes a new matrix. The number of elements must fit in an Int.

func (*Matrix) Data Uses

func (m *Matrix) Data() Vector

Data returns the data of the matrix as a vector.

func (Matrix) Eval Uses

func (m Matrix) Eval(Context) Value

func (Matrix) Inner Uses

func (m Matrix) Inner() Value

func (Matrix) ProgString Uses

func (m Matrix) ProgString() string

func (*Matrix) Shape Uses

func (m *Matrix) Shape() Vector

Shape returns the shape of the matrix.

func (Matrix) Sprint Uses

func (m Matrix) Sprint(conf *config.Config) string

func (Matrix) String Uses

func (m Matrix) String() string

type UnaryOp Uses

type UnaryOp interface {
    EvalUnary(c Context, right Value) Value
}

UnaryOp is the interface implemented by a simple unary operator.

type Value Uses

type Value interface {
    // String is for internal debugging only. It uses default configuration
    // and puts parentheses around every value so it's clear when it is used.
    // All user output should call Sprint instead.
    String() string
    Sprint(*config.Config) string
    Eval(Context) Value

    // Inner retrieves the value, without evaluation. But for Assignments,
    // it returns the right-hand side.
    Inner() Value

    // ProgString is like String, but suitable for program listing.
    // For instance, it ignores the user format for numbers and
    // puts quotes on chars, guaranteeing a correct representation.
    ProgString() string
    // contains filtered or unexported methods
}

func Parse Uses

func Parse(conf *config.Config, s string) (Value, error)

func Product Uses

func Product(c Context, u Value, op string, v Value) Value

Product computes a compound product, such as an inner product "+.*" or outer product "o.*". The op is known to contain a period. The operands are all at least vectors, and for inner product they must both be vectors.

func Reduce Uses

func Reduce(c Context, op string, v Value) Value

Reduce computes a reduction such as +/. The slash has been removed.

func Scan Uses

func Scan(c Context, op string, v Value) Value

Scan computes a scan of the op; the \ has been removed. It gives the successive values of reducing op through v. We must be right associative; that is the grammar.

type Vector Uses

type Vector []Value

func NewVector Uses

func NewVector(elem []Value) Vector

func (Vector) AllChars Uses

func (v Vector) AllChars() bool

AllChars reports whether the vector contains only Chars.

func (Vector) Copy Uses

func (v Vector) Copy() Vector

func (Vector) Eval Uses

func (v Vector) Eval(Context) Value

func (Vector) Inner Uses

func (v Vector) Inner() Value

func (Vector) ProgString Uses

func (v Vector) ProgString() string

func (Vector) Sprint Uses

func (v Vector) Sprint(conf *config.Config) string

func (Vector) String Uses

func (v Vector) String() string

Package value imports 9 packages (graph) and is imported by 10 packages. Updated 2017-06-03. Refresh now. Tools for package owners.