zc

package module
v6.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 23 Imported by: 0

README

zc

A fun stack-based calculator.

Use the browser version here:

https://blackchip-org.github.io/zc

Use tab to auto-complete. First tab completes an operation name as much as possible. Next tab shows matching candidates. When using on a mobile device, use the "tab" button to emulate pressing the tab button twice.

Example use:

https://blackchip-org.github.io/zc/?eval=1+8+seq+[2+sw+pow]+map

Documentation

Go Reference

ZC Demo

About

When I'm at a terminal prompt and I need to use a calculator, bc has always been my tool of choice. I thought it would be fun to write a calculator myself but with some items from my wish list built in. Those items are:

  • A stack-based calculator. Typing in a value places it on the stack. An operation consumes values on the stack and places its results back on the stack.
  • To minimize the use of the shift key. Instead of using + for addition, use add or a which is easier to type.
  • Use arbitrary sized integers and fixed point math by default. 1.1 2.2 add should be 3.3 and not 3.3000000000000003.
  • Be more than a simple calculator. Need an external tool to lookup, compute, or calculate? Put it in the calculator as a module instead. Make this calculator like a Swiss army knife.
  • Auto-complete!

This is the third iteration of this calculator and something fun to work on when time is available. It is a bit rough at this stage but should be useful nonetheless. Also, it will always be a bit rough--full of bugs and inconsistencies. Features get added as I need or think of them. Bugs get fixed or ignored as I see them. There is no grand plan beyond tinkering around for entertainment. Things may change in backwards incompatible ways with no notice.

Installation

For the command-line version, install go and then install the calculator with:

go install github.com/blackchip-org/zc/v6/cmd/zc@latest

Run the calculator with:

zc

Overview

Each line entered at the calculator prompt is divided into words. Each word is separated by whitespace. A word can be either a:

  • value: Starts with a numeric character, a decimal point, a numeric sign, or quotes. Values are placed onto the stack.
  • operation: Invokes a operation with the given name. Parameters are consumed from the stack and results are placed on the stack.

If 2 3 a is entered at the prompt, the values of 2 and 3 are placed on the stack, the a operation (for addition) is executed, the values are consumed and the result 5 is placed on the stack.

Examples of calculator use will be presented in a table such as:

Input Stack
2 3 a 5

The Input column shows the text entered at the prompt and the Stack column shows the contents of the stack after the line is evaluated. Each word could have been placed on a separate line:

Input Stack
2 2
3 2 | 3
a 5

If there are multiple items on the stack, they are notated by using a pipe | character to separate each item. The item on the right is the top of the stack.

If an operation does not change the stack a notification may be printed right above the prompt. This is indicated in the table by using italics.

Input Stack
0 rand.seed seed set to 0

The basic math functions are:

Function Description
add, a, + Addition
sub, s, - Subtraction
mul, m, * Multiplication
div, d, / Division

For each of these operations there are three separate names. For addition there is:

  • a: Easy to type without having to use the shift key
  • add: Easy to read in documentation
  • +: Easy to type if you have a keyboard with a number pad

Additional basic math functions can be found in the basic reference.

Example

Let's compute the distance between two points: (2, 3) and (5, 7). The formula for this uses the Pythagorean theorem:

dist = sqrt((x2 - x1)^2 + (y2 - y1)^2)

The steps are:

  • Compute x2 - x1
  • Square the result
  • Compute y2 - y1
  • Square the result
  • Add them together
  • Take the square root

The entry into the calculator looks like the following:

Input Stack
5 2 sub 3
2 pow 9
7 3 sub 9 | 4
2 pow 9 | 16
add 25
sqrt 5

Numbers

Thousand separators are ignored when parsing numbers:

Input Stack
65,536 sqrt 256

Currency symbols are also ignored when parsing:

Input Stack
$1234 2 mul 2468

Integer math uses arbitrary sized values when possible:

Input Stack
2 128 pow 340282366920938463463374607431768211456

Real number math uses fixed point math when possible:

Input Stack
1.1 2.2 a 3.3

To perform double precision floating-point operation, use add/f instead:

Input Stack
1.1 2.2 add/f 3.3000000000000003

Use either round or r to round to a certain number of digits after the decimal point:

Input Stack
1.1 2.2 add/f 3.3000000000000003
2 round 3.3

Enter fractions in a/b notation:

Input Stack
1/2 1/4 1/2 | 1/4
add 3/4

Prefix a whole number to a fraction with either a space, an underscore, or a hyphen:

Input Stack
2-1/2 3-1/4 2-1/2 | 3-1/4
add 5 3/4

Enter complex numbers in r+i notation:

Input Stack
1+2i 2+3i 1+2i | 2+3i
add 3+5i

Text

Text can be used as a value by either one of two ways. If the text does not contain any whitespace, the text can be prefixed with a slash, /. For example:

Input Stack
1 2 1 | 2
/add 1 | 2 | add

Otherwise, surround text with quotes. Single quotes, ' ', double quotes, " " or square brackets, [ ] can be used. If the text value is the only item on the line, an ending quote is not required. The following computes the length, in characters, of the given text:

Input Stack
'one thousand one thousand
len 12

Using brackets is convenient when nesting quoted values:

Input Stack
1 2 [[[add]]] 1 | 2 | [[add]]
eval 1 | 2 | [add]
eval 1 | 2 | add
eval 3

To use multiple lines as values (for example, when pasting the contents of the clipboard), use quote with a delimiter that marks the end of the values. Each line is considered a separate value when using quote. For example:

Input Stack
1 2 add 3
quote EOF 3
2 3 add 3 | 2 3 add
EOF 3 | 2 3 add

Annotations

Values on the stack may have annotations to provide some additional metadata. For example, distance calculations and conversions annotate the value with the unit of measure:

Input Stack
1 1 2 2 1 | 1 | 2 | 2
haversine 157225.4320380729 m
m-km 2 round 157.23 km

A unit annotation can manually be attached to a value using unit:

Input Stack
123 123
/m unit 123 m

A label can be attached using label:

Input Stack
42 42
[the answer] label the answer: 42

Annotations are typically discarded when a value is popped off the stack:

Input Stack
123 /m unit 123 m
20 sub 103

Macros

Let's say that you commonly have to compute a sales tax that is 5%. To compute the sales tax on something that costs $123:

Input Stack
$123 $123
dup $123 | $123
0.05 $123 | $123 | 0.05
mul $123 | 6.15
add 129.15

Repeated use of this pattern can be used with a macro:

Input Stack
def tax dup 0.05 mul macro 'tax' defined
$123 $123
tax add 129.15

The name of = is reserved for your macro use in bulk operations:

Input Stack
def = top f-c 2 round macro '=' defined
32 = 0 °C
68 = 20 °C
100 = 37.78 °C

No operations start with a . character and can be used for macro names. Play a game of rock, paper, scissors:

Input Stack
1 rand.seed seed set to 1
def .rps c 'rock' 'paper' 'scissors' rand.take macro '.rps' defined
.rps paper
.rps rock

Macros can also be used to override calculator operations. Undefine the macro by using def without an expression.

Input Stack
def pi 'Yum macro 'pi' overrides
pi Yum
def pi macro 'pi' undefined
pi 5 r Yum | 3.14159

Higher order functions

The map operation can be used to apply a function to each item on the stack. To use this operation, the top element of the stack should be an expression to evaluate. Place this expression on the stack using quotes to prevent immediate evaluation. For example, to double all numbers on the stack:

Input Stack
1 2 3 4 5 1 | 2 | 3 | 4 | 5
[2 mul 1 | 2 | 3 | 4 | 5 | 2 mul
map 2 | 4 | 6 | 8 | 10

The fold function can be used to reduce all items in the stack to a single value. For example, to sum all the numbers on the stack:

Input Stack
1 2 3 4 5 1 | 2 | 3 | 4 | 5
[add 1 | 2 | 3 | 4 | 5 | add
fold 15

Additional higher-order functions can be found in the hof reference.

Temporary Stack and Memory

It is sometimes convenient to store values in a temporary stack during a calcuation. The push operation removes the top item in the main stack and pushes it to the temproary stack. The pop operation does the inverse. For example, to compute an average, first get the length of the stack, push that to the temporary stack, sum the values, pop the length and then divide:

Input Stack
2 4 4 4 5 5 7 9 2 | 4 | 4 | 4 | 5 | 5 | 7 | 9
n 2 | 4 | 4 | 4 | 5 | 5 | 7 | 9 | 8
push 2 | 4 | 4 | 4 | 5 | 5 | 7 | 9
sum 40
pop 40 | 8
div 5

The push.all and pop.all operations transfers all items from one stack to the other. Use the flip operation to flip between the stacks.

Items on the main stack can also be stored to a named memory location to be recalled at a later time. Use store to copy the stack to memory and load to recall it.

Let's manually compute the population standard deviation found in the example on the Wikipedia page. The average of the all the data points must first be computed and then deviations from that average are calculated. This time the predefined average operation is used. The data is first entered into the calculator and then the stack is saved with the name of data. The average is then computed and stored with the name of av. The data points are then recalled from memory and the deviations from the average are calculated for each value. The standard deviation is then simply the square root of the average deviation.

Input Stack
2 4 4 4 5 5 7 9 2 | 4 | 4 | 4 | 5 | 5 | 7 | 9
/data st stored
avg 5
/av st stored
c /data ld 2 | 4 | 4 | 4 | 5 | 5 | 7 | 9
[/av ld sub sq] map 9 | 1 | 1 | 1 | 0 | 0 | 4 | 16
avg sqrt 2

The same calculation can be done using the temporary stack like this:

Input Stack
2 4 4 4 5 5 7 9 2 | 4 | 4 | 4 | 5 | 5 | 7 | 9
copy copied
avg 5
popa 5 | 2 | 4 | 4 | 4 | 5 | 5 | 7 | 9
up 2 | 4 | 4 | 4 | 5 | 5 | 7 | 9 | 5
[sub sq] /map 2 apply 9 | 1 | 1 | 1 | 0 | 0 | 4 | 16
avg sqrt 2

Commands

These commands are available when running the calculator interactively:

Command Description
blank line Remove the first item from stack
def Define a macro
redo Redo the last undo
reset Clear stacks, memory, and all state
quit Print the final stack and return to shell
quote Add each line to the stack until delimiter is found
undo, u Undo the last line entered

Command line

Any arguments found on the command line are passed to the calculator for a one-time evaluation:

$ zc 2 3 add
5

Using quotes from the command line can be tricky since they are interpreted by the shell:

$ zc 'foo' len
(!) unknown operation: foo

In this case, wrap the expression with quotes and then use square brackets for foo:

$ zc '[foo] len'
3

Use a single argument of - to read from standard input:

$ echo "2 3 add" | zc -
5

External Libraries

Some features of the calculator use external C libraries. The current release binaries do not include these external libraries and using one of these operations will raise a "feature not supported" error.

Ubuntu

For coordinate transform support, build with the proj tag and install proj with:

sudo apt install libproj-dev

Credits

License

MIT

Feedback

Contact me at [email protected]

Documentation

Index

Constants

View Source
const (
	TokenValue = "value"
	TokenName  = "name"
)
View Source
const (
	PrecFloat128 = 113
	PrecDec      = vars.DefaultDecPrec
)
View Source
const DefsDir = "app/defs"

Variables

View Source
var (
	AngleDMS = AngleDMSType{}
	Any      = AnyType{}
	BigFloat = BigFloatType{}
	BigInt   = BigIntType{}
	Bool     = BoolType{}
	Complex  = ComplexType{}
	Data     = DataType{}
	Date     = DateType{}
	DateTime = DateTimeType{}
	Decimal  = DecimalType{}
	Duration = DurationType{}
	Float64  = Float64Type{}
	Float32  = Float32Type{}
	Int      = IntType{}
	Int8     = Int8Type{}
	Int16    = Int16Type{}
	Int32    = Int32Type{}
	Int64    = Int64Type{}
	Rat      = RatType{}
	Real     = RealType{}
	String   = StringType{}
	Time     = TimeType{}
	Uint     = UintType{}
	Uint8    = Uint8Type{}
	Uint16   = Uint16Type{}
	Uint32   = Uint32Type{}
	Uint64   = Uint64Type{}
)
View Source
var Categories = []Category{
	{ID: "calc", Title: "Calculator Operations"},
	{ID: "unit", Title: "Units of Measure"},
	{ID: "lib", Title: "Library"},
	{ID: "tab", Title: "Tables"},
}
View Source
var Defs embed.FS

Functions

func Clamp

func Clamp[T cmp.Ordered](z T, a T, b T) T

func ConsoleLogger

func ConsoleLogger(e Event)

func FormatExponent

func FormatExponent(str string) string

func FormatItems

func FormatItems(items []Item) []string

func FormatList

func FormatList(vals []string) string

func IsFloatErr

func IsFloatErr(c Calc, f float64) bool

func IsValuePrefix

func IsValuePrefix(ch rune, next rune) bool

func PreParseDecimal

func PreParseDecimal(str string) string

func PreParseInt

func PreParseInt(str string) string

func ScanWords

func ScanWords(line string) []scan.Token

func Strings

func Strings(xs ...any) []string

func TestLogger

func TestLogger(t *testing.T) func(Event)

Types

type AngleDMSType

type AngleDMSType struct{}

----------------------------------------------------------------------------

func (AngleDMSType) AppName

func (t AngleDMSType) AppName() string

func (AngleDMSType) As

func (t AngleDMSType) As(a any) types.AngleDMS

func (AngleDMSType) Dup

func (t AngleDMSType) Dup(a any) any

func (AngleDMSType) Format

func (t AngleDMSType) Format(_ coll.State, a any) string

func (AngleDMSType) GoName

func (t AngleDMSType) GoName() string

func (AngleDMSType) Name

func (t AngleDMSType) Name() string

func (AngleDMSType) Parse

func (t AngleDMSType) Parse(state coll.State, str string) (any, bool, error)

func (AngleDMSType) Pop

func (t AngleDMSType) Pop(c Calc) types.AngleDMS

func (AngleDMSType) Push

func (t AngleDMSType) Push(c Calc, val types.AngleDMS)

type AnyType

type AnyType struct{}

----------------------------------------------------------------------------

func (AnyType) AppName

func (t AnyType) AppName() string

func (AnyType) Dup

func (t AnyType) Dup(a any) any

func (AnyType) Format

func (t AnyType) Format(_ coll.State, a any) string

func (AnyType) GoName

func (t AnyType) GoName() string

func (AnyType) Name

func (t AnyType) Name() string

func (AnyType) Parse

func (t AnyType) Parse(_ coll.State, str string) (any, bool, error)

type BigFloatType

type BigFloatType struct{}

----------------------------------------------------------------------------

func (BigFloatType) AppName

func (t BigFloatType) AppName() string

func (BigFloatType) As

func (t BigFloatType) As(a any) *big.Float

func (BigFloatType) Dup

func (t BigFloatType) Dup(a any) any

func (BigFloatType) Format

func (t BigFloatType) Format(_ coll.State, a any) string

func (BigFloatType) GoName

func (t BigFloatType) GoName() string

func (BigFloatType) Name

func (t BigFloatType) Name() string

func (BigFloatType) New

func (t BigFloatType) New(prec uint) *big.Float

func (BigFloatType) Parse

func (t BigFloatType) Parse(st coll.State, str string) (any, bool, error)

func (BigFloatType) Pop

func (t BigFloatType) Pop(c Calc) *big.Float

func (BigFloatType) Push

func (t BigFloatType) Push(c Calc, val *big.Float)

func (BigFloatType) Recycle

func (t BigFloatType) Recycle(vals ...*big.Float)

type BigIntType

type BigIntType struct{}

----------------------------------------------------------------------------

func (BigIntType) AppName

func (t BigIntType) AppName() string

func (BigIntType) As

func (t BigIntType) As(a any) *big.Int

func (BigIntType) Dup

func (t BigIntType) Dup(a any) any

func (BigIntType) Format

func (t BigIntType) Format(_ coll.State, a any) string

func (BigIntType) GoName

func (t BigIntType) GoName() string

func (BigIntType) Name

func (t BigIntType) Name() string

func (BigIntType) New

func (t BigIntType) New() *big.Int

func (BigIntType) Parse

func (t BigIntType) Parse(_ coll.State, str string) (any, bool, error)

func (BigIntType) Pop

func (t BigIntType) Pop(c Calc) *big.Int

func (BigIntType) Push

func (t BigIntType) Push(c Calc, val *big.Int)

func (BigIntType) Recycle

func (t BigIntType) Recycle(vals ...*big.Int)

type BoolType

type BoolType struct{}

----------------------------------------------------------------------------

func (BoolType) AppName

func (t BoolType) AppName() string

func (BoolType) As

func (t BoolType) As(a any) bool

func (BoolType) Dup

func (t BoolType) Dup(a any) any

func (BoolType) Format

func (t BoolType) Format(_ coll.State, a any) string

func (BoolType) GoName

func (t BoolType) GoName() string

func (BoolType) Name

func (t BoolType) Name() string

func (BoolType) Parse

func (t BoolType) Parse(_ coll.State, str string) (any, bool, error)

func (BoolType) Pop

func (t BoolType) Pop(c Calc) bool

func (BoolType) Push

func (t BoolType) Push(c Calc, val bool)

type Calc

type Calc interface {
	Push(...Item)
	Pop() Item
	Stack() []Item
	SetStack([]Item)
	Len() int
	String() string
	Var(string) (any, bool)
	NewVar(string, any)
	Notify(string, ...any)
	Raise(error)
	Label() string
	Unit() string
	SetLabel(string)
	SetUnit(string)
	Eval(string) error
	New() Calc
	Temp() []Item
	SetTemp([]Item)
	Store(string)
	Load(string)
	Reset()
}

type Catalog

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

func NewCatalog

func NewCatalog() *Catalog

func (*Catalog) AddMacro

func (c *Catalog) AddMacro(name string, mac string)

func (*Catalog) AddOp

func (c *Catalog) AddOp(ops ...Op)

func (*Catalog) AddVol

func (c *Catalog) AddVol(vols ...Vol)

func (*Catalog) OpFor

func (c *Catalog) OpFor(name string) (Op, bool)

func (*Catalog) OpNames

func (c *Catalog) OpNames() []string

type Category

type Category struct {
	ID    string
	Title string
}

type ComplexType

type ComplexType struct{}

----------------------------------------------------------------------------

func (ComplexType) AppName

func (t ComplexType) AppName() string

func (ComplexType) As

func (t ComplexType) As(a any) complex128

func (ComplexType) Dup

func (t ComplexType) Dup(a any) any

func (ComplexType) Format

func (t ComplexType) Format(_ coll.State, a any) string

func (ComplexType) GoName

func (t ComplexType) GoName() string

func (ComplexType) Name

func (t ComplexType) Name() string

func (ComplexType) Parse

func (t ComplexType) Parse(_ coll.State, str string) (any, bool, error)

func (ComplexType) Pop

func (t ComplexType) Pop(c Calc) complex128

func (ComplexType) Push

func (t ComplexType) Push(c Calc, val complex128)

type DataType

type DataType struct{}

----------------------------------------------------------------------------

func (DataType) AppName

func (t DataType) AppName() string

func (DataType) As

func (t DataType) As(a any) *bytes.Buffer

func (DataType) Dup

func (t DataType) Dup(a any) any

func (DataType) Format

func (t DataType) Format(_ coll.State, a any) string

func (DataType) GoName

func (t DataType) GoName() string

func (DataType) Name

func (t DataType) Name() string

func (DataType) New

func (t DataType) New() *bytes.Buffer

func (DataType) Parse

func (t DataType) Parse(_ coll.State, str string) (any, bool, error)

func (DataType) Pop

func (t DataType) Pop(c Calc) *bytes.Buffer

func (DataType) Push

func (t DataType) Push(c Calc, val *bytes.Buffer)

func (DataType) Recycle

func (t DataType) Recycle(vals ...*bytes.Buffer)

type DateTimeType

type DateTimeType struct{}

----------------------------------------------------------------------------

func (DateTimeType) AppName

func (t DateTimeType) AppName() string

func (DateTimeType) As

func (t DateTimeType) As(a any) time.Time

func (DateTimeType) Dup

func (t DateTimeType) Dup(a any) any

func (DateTimeType) Format

func (t DateTimeType) Format(state coll.State, a any) string

func (DateTimeType) GoName

func (t DateTimeType) GoName() string

func (DateTimeType) Name

func (t DateTimeType) Name() string

func (DateTimeType) Parse

func (t DateTimeType) Parse(state coll.State, str string) (any, bool, error)

func (DateTimeType) Pop

func (t DateTimeType) Pop(c Calc) time.Time

func (DateTimeType) Push

func (t DateTimeType) Push(c Calc, val time.Time)

type DateType

type DateType struct{}

----------------------------------------------------------------------------

func (DateType) AppName

func (t DateType) AppName() string

func (DateType) As

func (t DateType) As(a any) time.Time

func (DateType) Dup

func (t DateType) Dup(a any) any

func (DateType) Format

func (t DateType) Format(state coll.State, a any) string

func (DateType) GoName

func (t DateType) GoName() string

func (DateType) Name

func (t DateType) Name() string

func (DateType) Parse

func (t DateType) Parse(state coll.State, str string) (any, bool, error)

func (DateType) Pop

func (t DateType) Pop(c Calc) time.Time

func (DateType) Push

func (t DateType) Push(c Calc, val time.Time)

type DecimalType

type DecimalType struct{}

----------------------------------------------------------------------------

func (DecimalType) AppName

func (t DecimalType) AppName() string

func (DecimalType) As

func (t DecimalType) As(a any) *apd.Decimal

func (DecimalType) Dup

func (t DecimalType) Dup(a any) any

func (DecimalType) Format

func (t DecimalType) Format(_ coll.State, a any) string

func (DecimalType) GoName

func (t DecimalType) GoName() string

func (DecimalType) Name

func (t DecimalType) Name() string

func (DecimalType) New

func (t DecimalType) New() *apd.Decimal

func (DecimalType) Parse

func (t DecimalType) Parse(state coll.State, str string) (any, bool, error)

func (DecimalType) Pop

func (t DecimalType) Pop(c Calc) *apd.Decimal

func (DecimalType) Push

func (t DecimalType) Push(c Calc, val *apd.Decimal)

func (DecimalType) Recycle

func (t DecimalType) Recycle(vals ...*apd.Decimal)

type DurationType

type DurationType struct{}

----------------------------------------------------------------------------

func (DurationType) AppName

func (t DurationType) AppName() string

func (DurationType) As

func (t DurationType) As(a any) time.Duration

func (DurationType) Dup

func (t DurationType) Dup(a any) any

func (DurationType) Format

func (t DurationType) Format(_ coll.State, a any) string

func (DurationType) GoName

func (t DurationType) GoName() string

func (DurationType) Name

func (t DurationType) Name() string

func (DurationType) Parse

func (t DurationType) Parse(_ coll.State, str string) (any, bool, error)

func (DurationType) Pop

func (t DurationType) Pop(c Calc) time.Duration

func (DurationType) Push

func (t DurationType) Push(c Calc, val time.Duration)

type Event

type Event interface {
	Type() string
	String() string
}

type Expect

type Expect struct {
	Input  string   `yaml:"i"`
	Output []string `yaml:"o"`
	Error  string   `yaml:"error"`
	Notice string   `yaml:"notice"`
}

type Float32Type

type Float32Type struct{}

----------------------------------------------------------------------------

func (Float32Type) AppName

func (t Float32Type) AppName() string

func (Float32Type) As

func (t Float32Type) As(a any) float32

func (Float32Type) Dup

func (t Float32Type) Dup(a any) any

func (Float32Type) Format

func (t Float32Type) Format(_ coll.State, a any) string

func (Float32Type) GoName

func (t Float32Type) GoName() string

func (Float32Type) Name

func (t Float32Type) Name() string

func (Float32Type) Parse

func (t Float32Type) Parse(_ coll.State, str string) (any, bool, error)

func (Float32Type) Pop

func (t Float32Type) Pop(c Calc) float32

func (Float32Type) Push

func (t Float32Type) Push(c Calc, val float32)

type Float64Type

type Float64Type struct{}

----------------------------------------------------------------------------

func (Float64Type) AppName

func (t Float64Type) AppName() string

func (Float64Type) As

func (t Float64Type) As(a any) float64

func (Float64Type) Dup

func (t Float64Type) Dup(a any) any

func (Float64Type) Format

func (t Float64Type) Format(_ coll.State, a any) string

func (Float64Type) GoName

func (t Float64Type) GoName() string

func (Float64Type) Name

func (t Float64Type) Name() string

func (Float64Type) Parse

func (t Float64Type) Parse(_ coll.State, str string) (any, bool, error)

func (Float64Type) Pop

func (t Float64Type) Pop(c Calc) float64

func (Float64Type) Push

func (t Float64Type) Push(c Calc, val float64)

type Func

type Func struct {
	Params    []Type
	VarParam  Type
	Returns   []Type
	VarReturn Type
	Eval      func(Calc)
}

type FuncDef

type FuncDef struct {
	Name    string   `yaml:"name"`
	Ident   string   `yaml:"ident"`
	Params  []string `yaml:"params"`
	Returns []string `yaml:"returns"`
}

type Int16Type

type Int16Type struct{}

----------------------------------------------------------------------------

func (Int16Type) AppName

func (t Int16Type) AppName() string

func (Int16Type) As

func (t Int16Type) As(a any) int16

func (Int16Type) Dup

func (t Int16Type) Dup(a any) any

func (Int16Type) Format

func (t Int16Type) Format(_ coll.State, a any) string

func (Int16Type) GoName

func (t Int16Type) GoName() string

func (Int16Type) Name

func (t Int16Type) Name() string

func (Int16Type) Parse

func (t Int16Type) Parse(_ coll.State, str string) (any, bool, error)

func (Int16Type) Pop

func (t Int16Type) Pop(c Calc) int16

func (Int16Type) Push

func (t Int16Type) Push(c Calc, val int16)

type Int32Type

type Int32Type struct{}

----------------------------------------------------------------------------

func (Int32Type) AppName

func (t Int32Type) AppName() string

func (Int32Type) As

func (t Int32Type) As(a any) int32

func (Int32Type) Dup

func (t Int32Type) Dup(a any) any

func (Int32Type) Format

func (t Int32Type) Format(_ coll.State, a any) string

func (Int32Type) GoName

func (t Int32Type) GoName() string

func (Int32Type) Name

func (t Int32Type) Name() string

func (Int32Type) Parse

func (t Int32Type) Parse(_ coll.State, str string) (any, bool, error)

func (Int32Type) Pop

func (t Int32Type) Pop(c Calc) int32

func (Int32Type) Push

func (t Int32Type) Push(c Calc, val int32)

type Int64Type

type Int64Type struct{}

----------------------------------------------------------------------------

func (Int64Type) AppName

func (t Int64Type) AppName() string

func (Int64Type) As

func (t Int64Type) As(a any) int64

func (Int64Type) Dup

func (t Int64Type) Dup(a any) any

func (Int64Type) Format

func (t Int64Type) Format(_ coll.State, a any) string

func (Int64Type) GoName

func (t Int64Type) GoName() string

func (Int64Type) Name

func (t Int64Type) Name() string

func (Int64Type) Parse

func (t Int64Type) Parse(_ coll.State, str string) (any, bool, error)

func (Int64Type) Pop

func (t Int64Type) Pop(c Calc) int64

func (Int64Type) Push

func (t Int64Type) Push(c Calc, val int64)

type Int8Type

type Int8Type struct{}

----------------------------------------------------------------------------

func (Int8Type) AppName

func (t Int8Type) AppName() string

func (Int8Type) As

func (t Int8Type) As(a any) int8

func (Int8Type) Dup

func (t Int8Type) Dup(a any) any

func (Int8Type) Format

func (t Int8Type) Format(_ coll.State, a any) string

func (Int8Type) GoName

func (t Int8Type) GoName() string

func (Int8Type) Name

func (t Int8Type) Name() string

func (Int8Type) Parse

func (t Int8Type) Parse(_ coll.State, str string) (any, bool, error)

func (Int8Type) Pop

func (t Int8Type) Pop(c Calc) int8

func (Int8Type) Push

func (t Int8Type) Push(c Calc, val int8)

type IntType

type IntType struct{}

----------------------------------------------------------------------------

func (IntType) AppName

func (t IntType) AppName() string

func (IntType) As

func (t IntType) As(a any) int

func (IntType) Dup

func (t IntType) Dup(a any) any

func (IntType) Format

func (t IntType) Format(_ coll.State, a any) string

func (IntType) GoName

func (t IntType) GoName() string

func (IntType) Name

func (t IntType) Name() string

func (IntType) Parse

func (t IntType) Parse(_ coll.State, str string) (any, bool, error)

func (IntType) Pop

func (t IntType) Pop(c Calc) int

func (IntType) Push

func (t IntType) Push(c Calc, val int)

type Item

type Item struct {
	TypeVal any
	Type    Type

	Unit  string
	Label string
	// contains filtered or unexported fields
}

func DupItems

func DupItems(items []Item) []Item

func (Item) Dup

func (i Item) Dup() Item

func (Item) String

func (i Item) String() string

func (Item) Val

func (i Item) Val() string

type Listener

type Listener func(Event)

type Macro

type Macro struct {
	Name string
	Expr string
}

type Op

type Op struct {
	Name  string
	Funcs []Func
	Macro []scan.Token
}

type OpDef

type OpDef struct {
	Name     string    `yaml:"name"`
	Ident    string    `yaml:"ident"`
	Aliases  []string  `yaml:"aliases"`
	Title    string    `yaml:"title"`
	Subtitle string    `yaml:"subtitle"`
	Stub     bool      `yaml:"stub"`
	Funcs    []FuncDef `yaml:"funcs"`
	Macro    string    `yaml:"macro"`
	Desc     string    `yaml:"desc"`
	Example  []Expect  `yaml:"example"`
	Tests    []Test    `yaml:"tests"`
}

type OpEvent

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

func NewOpEvent

func NewOpEvent(name string) OpEvent

func (OpEvent) String

func (e OpEvent) String() string

func (OpEvent) Type

func (e OpEvent) Type() string

type RatType

type RatType struct{}

----------------------------------------------------------------------------

func (RatType) AppName

func (t RatType) AppName() string

func (RatType) As

func (t RatType) As(a any) *big.Rat

func (RatType) Dup

func (t RatType) Dup(a any) any

func (RatType) Format

func (t RatType) Format(_ coll.State, a any) string

func (RatType) GoName

func (t RatType) GoName() string

func (RatType) Name

func (t RatType) Name() string

func (RatType) New

func (t RatType) New() *big.Rat

func (RatType) Parse

func (t RatType) Parse(_ coll.State, str string) (any, bool, error)

func (RatType) Pop

func (t RatType) Pop(c Calc) *big.Rat

func (RatType) Push

func (t RatType) Push(c Calc, val *big.Rat)

func (RatType) Recycle

func (t RatType) Recycle(vals ...*big.Rat)

type RealType

type RealType struct{}

----------------------------------------------------------------------------

func (RealType) AppName

func (t RealType) AppName() string

func (RealType) Dup

func (t RealType) Dup(a any) any

func (RealType) Format

func (t RealType) Format(s coll.State, a any) string

func (RealType) GoName

func (t RealType) GoName() string

func (RealType) Name

func (t RealType) Name() string

func (RealType) Parse

func (t RealType) Parse(s coll.State, str string) (any, bool, error)

type StackEvent

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

func NewStackEvent

func NewStackEvent(c Calc, type_ string) StackEvent

func (StackEvent) String

func (e StackEvent) String() string

func (StackEvent) Type

func (e StackEvent) Type() string

type State

type State interface {
	State(string) (any, bool)
	NewState(string, any)
}

type StringType

type StringType struct{}

----------------------------------------------------------------------------

func (StringType) AppName

func (t StringType) AppName() string

func (StringType) As

func (t StringType) As(a any) string

func (StringType) Dup

func (t StringType) Dup(a any) any

func (StringType) Format

func (t StringType) Format(_ coll.State, a any) string

func (StringType) GoName

func (t StringType) GoName() string

func (StringType) Name

func (t StringType) Name() string

func (StringType) Parse

func (t StringType) Parse(_ coll.State, str string) (any, bool, error)

func (StringType) Pop

func (t StringType) Pop(c Calc) string

func (StringType) Push

func (t StringType) Push(c Calc, val string)

type Test

type Test struct {
	Name string   `yaml:"name"`
	Test []Expect `yaml:"test"`
}

type TimeType

type TimeType struct{}

----------------------------------------------------------------------------

func (TimeType) AppName

func (t TimeType) AppName() string

func (TimeType) As

func (t TimeType) As(a any) time.Time

func (TimeType) Dup

func (t TimeType) Dup(a any) any

func (TimeType) Format

func (t TimeType) Format(state coll.State, a any) string

func (TimeType) GoName

func (t TimeType) GoName() string

func (TimeType) Name

func (t TimeType) Name() string

func (TimeType) Parse

func (t TimeType) Parse(state coll.State, str string) (any, bool, error)

func (TimeType) Pop

func (t TimeType) Pop(c Calc) time.Time

func (TimeType) Push

func (t TimeType) Push(c Calc, val time.Time)

type Type

type Type interface {
	Name() string
	AppName() string
	GoName() string
	Parse(coll.State, string) (any, bool, error)
	Format(coll.State, any) string
	Dup(any) any
}

type Uint16Type

type Uint16Type struct{}

----------------------------------------------------------------------------

func (Uint16Type) AppName

func (t Uint16Type) AppName() string

func (Uint16Type) As

func (t Uint16Type) As(a any) uint16

func (Uint16Type) Dup

func (t Uint16Type) Dup(a any) any

func (Uint16Type) Format

func (t Uint16Type) Format(_ coll.State, a any) string

func (Uint16Type) GoName

func (t Uint16Type) GoName() string

func (Uint16Type) Name

func (t Uint16Type) Name() string

func (Uint16Type) Parse

func (t Uint16Type) Parse(_ coll.State, str string) (any, bool, error)

func (Uint16Type) Pop

func (t Uint16Type) Pop(c Calc) uint16

func (Uint16Type) Push

func (t Uint16Type) Push(c Calc, val uint16)

type Uint32Type

type Uint32Type struct{}

----------------------------------------------------------------------------

func (Uint32Type) AppName

func (t Uint32Type) AppName() string

func (Uint32Type) As

func (t Uint32Type) As(a any) uint32

func (Uint32Type) Dup

func (t Uint32Type) Dup(a any) any

func (Uint32Type) Format

func (t Uint32Type) Format(_ coll.State, a any) string

func (Uint32Type) GoName

func (t Uint32Type) GoName() string

func (Uint32Type) Name

func (t Uint32Type) Name() string

func (Uint32Type) Parse

func (t Uint32Type) Parse(_ coll.State, str string) (any, bool, error)

func (Uint32Type) Pop

func (t Uint32Type) Pop(c Calc) uint32

func (Uint32Type) Push

func (t Uint32Type) Push(c Calc, val uint32)

type Uint64Type

type Uint64Type struct{}

----------------------------------------------------------------------------

func (Uint64Type) AppName

func (t Uint64Type) AppName() string

func (Uint64Type) As

func (t Uint64Type) As(a any) uint64

func (Uint64Type) Dup

func (t Uint64Type) Dup(a any) any

func (Uint64Type) Format

func (t Uint64Type) Format(_ coll.State, a any) string

func (Uint64Type) GoName

func (t Uint64Type) GoName() string

func (Uint64Type) Name

func (t Uint64Type) Name() string

func (Uint64Type) Parse

func (t Uint64Type) Parse(_ coll.State, str string) (any, bool, error)

func (Uint64Type) Pop

func (t Uint64Type) Pop(c Calc) uint64

func (Uint64Type) Push

func (t Uint64Type) Push(c Calc, val uint64)

type Uint8Type

type Uint8Type struct{}

----------------------------------------------------------------------------

func (Uint8Type) AppName

func (t Uint8Type) AppName() string

func (Uint8Type) As

func (t Uint8Type) As(a any) uint8

func (Uint8Type) Dup

func (t Uint8Type) Dup(a any) any

func (Uint8Type) Format

func (t Uint8Type) Format(_ coll.State, a any) string

func (Uint8Type) GoName

func (t Uint8Type) GoName() string

func (Uint8Type) Name

func (t Uint8Type) Name() string

func (Uint8Type) Parse

func (t Uint8Type) Parse(_ coll.State, str string) (any, bool, error)

func (Uint8Type) Pop

func (t Uint8Type) Pop(c Calc) uint8

func (Uint8Type) Push

func (t Uint8Type) Push(c Calc, val uint8)

type UintType

type UintType struct{}

----------------------------------------------------------------------------

func (UintType) AppName

func (t UintType) AppName() string

func (UintType) As

func (t UintType) As(a any) uint

func (UintType) Dup

func (t UintType) Dup(a any) any

func (UintType) Format

func (t UintType) Format(_ coll.State, a any) string

func (UintType) GoName

func (t UintType) GoName() string

func (UintType) Name

func (t UintType) Name() string

func (UintType) Parse

func (t UintType) Parse(_ coll.State, str string) (any, bool, error)

func (UintType) Pop

func (t UintType) Pop(c Calc) uint

func (UintType) Push

func (t UintType) Push(c Calc, val uint)

type Vol

type Vol struct {
	Name   string
	Ops    []Op
	Macros []Macro
}

type VolDef

type VolDef struct {
	Name     string     `yaml:"name"`
	Ident    string     `yaml:"ident"`
	Title    string     `yaml:"title"`
	Subtitle string     `yaml:"subtitle"`
	Category string     `yaml:"category"`
	NoIndex  bool       `yaml:"no-index"`
	Setup    []string   `yaml:"setup"`
	Ops      []OpDef    `yaml:"ops"`
	Table    [][]string `yaml:"table"`
	Overview string
}

func LoadDefs

func LoadDefs() ([]VolDef, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳