operators

package
v0.66.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2020 License: AGPL-3.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Add = numericalBinary(func(env envs.Environment, num1 types.XNumber, num2 types.XNumber) types.XValue {
	return types.NewXNumber(num1.Native().Add(num2.Native()))
})

Add adds two numbers.

@(2 + 3) -> 5
@(fields.age + 10) -> 33

@operator add

View Source
var Concatenate = textualBinary(func(env envs.Environment, text1 types.XText, text2 types.XText) types.XValue {
	var buffer strings.Builder
	buffer.WriteString(text1.Native())
	buffer.WriteString(text2.Native())
	return types.NewXText(buffer.String())
})

Concatenate joins two text values together.

@("hello" & " " & "bar") -> hello bar
@("hello" & null) -> hello

@operator concatenate

View Source
var Divide = numericalBinary(func(env envs.Environment, num1 types.XNumber, num2 types.XNumber) types.XValue {
	if num2.Equals(types.XNumberZero) {
		return types.NewXErrorf("division by zero")
	}

	return types.NewXNumber(num1.Native().Div(num2.Native()))
})

Divide divides a number by another.

@(4 / 2) -> 2
@(3 / 2) -> 1.5
@(46 / fields.age) -> 2
@(3 / 0) -> ERROR

@operator divide

View Source
var Equal = textualBinary(func(env envs.Environment, text1 types.XText, text2 types.XText) types.XValue {
	return types.NewXBoolean(text1.Equals(text2))
})

Equal returns true if two values are textually equal.

@("hello" = "hello") -> true
@("hello" = "bar") -> false
@(1 = 1) -> true

@operator equal

View Source
var Exponent = numericalBinary(func(env envs.Environment, num1 types.XNumber, num2 types.XNumber) types.XValue {
	return types.NewXNumber(num1.Native().Pow(num2.Native()))
})

Exponent raises a number to the power of a another number.

@(2 ^ 8) -> 256

@operator exponent

View Source
var GreaterThan = numericalBinary(func(env envs.Environment, num1 types.XNumber, num2 types.XNumber) types.XValue {
	return types.NewXBoolean(num1.Compare(num2) > 0)
})

GreaterThan returns true if the first number is greater than the second.

@(2 > 3) -> false
@(3 > 3) -> false
@(4 > 3) -> true

@operator greaterthan

View Source
var GreaterThanOrEqual = numericalBinary(func(env envs.Environment, num1 types.XNumber, num2 types.XNumber) types.XValue {
	return types.NewXBoolean(num1.Compare(num2) >= 0)
})

GreaterThanOrEqual returns true if the first number is greater than or equal to the second.

@(2 >= 3) -> false
@(3 >= 3) -> true
@(4 >= 3) -> true

@operator greaterthanorequal

View Source
var LessThan = numericalBinary(func(env envs.Environment, num1 types.XNumber, num2 types.XNumber) types.XValue {
	return types.NewXBoolean(num1.Compare(num2) < 0)
})

LessThan returns true if the first number is less than the second.

@(2 < 3) -> true
@(3 < 3) -> false
@(4 < 3) -> false

@operator lessthan

View Source
var LessThanOrEqual = numericalBinary(func(env envs.Environment, num1 types.XNumber, num2 types.XNumber) types.XValue {
	return types.NewXBoolean(num1.Compare(num2) <= 0)
})

LessThanOrEqual returns true if the first number is less than or equal to the second.

@(2 <= 3) -> true
@(3 <= 3) -> true
@(4 <= 3) -> false

@operator lessthanorequal

View Source
var Multiply = numericalBinary(func(env envs.Environment, num1 types.XNumber, num2 types.XNumber) types.XValue {
	return types.NewXNumber(num1.Native().Mul(num2.Native()))
})

Multiply multiplies two numbers.

@(3 * 2) -> 6
@(fields.age * 3) -> 69

@operator multiply

View Source
var Negate = numericalUnary(func(env envs.Environment, num types.XNumber) types.XValue {
	return types.NewXNumber(num.Native().Neg())
})

Negate negates a number

@(-fields.age) -> -23

@operator negate

View Source
var NotEqual = textualBinary(func(env envs.Environment, text1 types.XText, text2 types.XText) types.XValue {
	return types.NewXBoolean(!text1.Equals(text2))
})

NotEqual returns true if two values are textually not equal.

@("hello" != "hello") -> false
@("hello" != "bar") -> true
@(1 != 2) -> true

@operator notequal

View Source
var Subtract = numericalBinary(func(env envs.Environment, num1 types.XNumber, num2 types.XNumber) types.XValue {
	return types.NewXNumber(num1.Native().Sub(num2.Native()))
})

Subtract subtracts two numbers.

@(3 - 2) -> 1
@(2 - 3) -> -1

@operator subtract

Functions

This section is empty.

Types

type BinaryOperator

type BinaryOperator func(envs.Environment, types.XValue, types.XValue) types.XValue

BinaryOperator is an operator which takes two arguments

type UnaryOperator

type UnaryOperator func(envs.Environment, types.XValue) types.XValue

UnaryOperator is an operator which takes a single argument

Jump to

Keyboard shortcuts

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