builtin

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TyBool = tyBool(0)

TyBool represents the `bool` type.

View Source
var TyByte = TyUint8

TyByte represents the `byte` type.

View Source
var TyFloat = TyFloat64

TyFloat represents the `float` type.

View Source
var TyFloat32 = tyFloat32(0)

TyFloat32 represents the `float32` type.

View Source
var TyFloat64 = tyFloat64(0)

TyFloat64 represents the `float64` type.

View Source
var TyInt = tyInt(0)

TyInt represents the `int` type.

View Source
var TyInt16 = tyInt16(0)

TyInt16 represents the `int16` type.

View Source
var TyInt32 = tyInt32(0)

TyInt32 represents the `int32` type.

View Source
var TyInt64 = tyInt64(0)

TyInt64 represents the `int64` type.

View Source
var TyInt8 = tyInt8(0)

TyInt8 represents the `int8` type.

View Source
var TyString = tyString(0)

TyString represents the `string` type.

View Source
var TyUint = tyUint(0)

TyUint represents the `uint` type.

View Source
var TyUint16 = tyUint16(0)

TyUint16 represents the `uint16` type.

View Source
var TyUint32 = tyUint32(0)

TyUint32 represents the `uint32` type.

View Source
var TyUint64 = tyUint64(0)

TyUint64 represents the `uint64` type.

View Source
var TyUint8 = tyUint8(0)

TyUint8 represents the `uint8` type.

View Source
var TyVar = tyVar(0)

TyVar represents the `var` type.

View Source
var YaklangBaseLib = map[string]interface{}{
	"append":    Append,
	"copy":      Copy,
	"delete":    Delete,
	"get":       Get,
	"len":       Len,
	"cap":       Cap,
	"mkmap":     Mkmap,
	"mapFrom":   MapFrom,
	"mapOf":     MapOf,
	"mkslice":   Mkslice,
	"slice":     Mkslice,
	"sliceFrom": SliceFrom,
	"sliceOf":   SliceOf,
	"sub":       SubSlice,
	"panic":     Panic,
	"panicf":    Panicf,
	"print":     print,
	"printf":    printf,
	"println":   println,
	"sprint":    sprint,
	"sprintf":   sprintf,
	"sprintln":  sprintln,
	"fprint":    fprint,
	"fprintf":   fprintf,
	"fprintln":  fprintln,
	"set":       Set,
	"make":      Make,
	"close":     CloseChan,

	"float":   TyFloat64,
	"float64": TyFloat64,
	"float32": TyFloat32,
	"int8":    TyInt8,
	"int16":   TyInt16,
	"int32":   TyInt32,
	"int64":   TyInt64,
	"int":     TyInt,
	"uint":    TyUint,
	"byte":    TyUint8,
	"uint8":   TyUint8,
	"uint16":  TyUint16,
	"uint32":  TyUint32,
	"uint64":  TyUint64,
	"string":  TyString,
	"bool":    TyBool,
	"var":     TyVar,

	"max": Max,
	"min": Min,

	"undefined": yaklangspec.Undefined,
	"nil":       nil,
	"true":      true,
	"false":     false,

	"$elem":    Elem,
	"$neg":     Neg,
	"$mul":     Mul,
	"$quo":     Quo,
	"$mod":     Mod,
	"$add":     Add,
	"$sub":     Sub,
	"$ternary": Ternary,
	"$in":      In,

	"$xor":    Xor,
	"$lshr":   Lshr,
	"$rshr":   Rshr,
	"$bitand": BitAnd,
	"$bitor":  BitOr,
	"$bitnot": BitNot,
	"$andnot": AndNot,

	"$lt":  LT,
	"$gt":  GT,
	"$le":  LE,
	"$ge":  GE,
	"$eq":  EQ,
	"$ne":  NE,
	"$not": Not,
}

Functions

func Add

func Add(a, b interface{}) interface{}

Add returns a+b

func AndNot

func AndNot(a, b interface{}) interface{}

AndNot returns a &^ b

func Append

func Append(a interface{}, vals ...interface{}) (ret interface{})

append 将元素追加到数组或切片中,并将结果返回 Example: ``` a = [1, 2, 3] a = append(a, 4, 5, 6) println(a) // [1 2 3 4 5 6] ```

func BitAnd

func BitAnd(a, b interface{}) interface{}

BitAnd returns a & b

func BitNot

func BitNot(a interface{}) interface{}

BitNot returns ^a

func BitOr

func BitOr(a, b interface{}) interface{}

BitOr returns a | b

func Bool

func Bool(a interface{}) bool

Bool returns bool(a)

func Cap

func Cap(a interface{}) int

cap 返回集合对象的容量,对象可以是数组(array),切片(slice)或通道(channel) Example: ``` a = make([]int, 0, 3) println(cap(a)) // 3 ```

func CloseChan

func CloseChan(v interface{})

close 用于关闭已经打开的通道(channel),关闭一个已经关闭的通道会导致运行时崩溃 Example: ``` ch = make(chan int) go func() { for i = range ch { println(i) } }() ch <- 1 ch <- 2 close(ch) ```

func Copy

func Copy(dst, src interface{}) int

copy 将 src 数组/切片复制到 dst 数组/切片中,并返回复制的元素个数 Example: ``` a = [1, 2, 3] b = make([]int, 3) copy(b, a) println(b) // [1 2 3] ```

func Dec

func Dec(a interface{}) interface{}

Dec returns a-1

func Delete

func Delete(m interface{}, key interface{})

delete 从map中删除key Example: ``` m = {"a": 1, "b": 2} delete(m, "b") println(m) // {"a": 1} ```

func EQ

func EQ(a, b interface{}) interface{}

func Elem

func Elem(a interface{}) interface{}

Elem returns *a

func Float32

func Float32(a interface{}) float32

Float32 returns float32(a)

func Float64

func Float64(a interface{}) float64

Float64 returns float64(a)

func GE

func GE(a, b interface{}) interface{}

GE returns a >= b

func GT

func GT(a, b interface{}) interface{}

GT returns a > b

func Get

func Get(m interface{}, key interface{}, defaultValues ...interface{}) (result interface{})

get 从map中获取键值,如果键不存在,则返回默认值 Example: ``` m = {"a": 1, "b": 2} get(m, "a") // 1 get(m, "c", "default") // "default" ```

func GetVar

func GetVar(m interface{}, key interface{}) interface{}

GetVar returns a member variable of an object. object can be a slice, an array, a map or a user-defined class.

func In

func In(a, b interface{}) interface{}

In

func Inc

func Inc(a interface{}) interface{}

Inc returns a+1

func Int

func Int(a interface{}) int

Int returns int(a)

func Int16

func Int16(a interface{}) int16

Int16 returns int16(a)

func Int32

func Int32(a interface{}) int32

Int32 returns int32(a)

func Int64

func Int64(a interface{}) int64

Int64 returns int64(a)

func Int8

func Int8(a interface{}) int8

Int8 returns int8(a)

func LE

func LE(a, b interface{}) interface{}

LE returns a <= b

func LT

func LT(a, b interface{}) interface{}

LT returns a < b

func Len

func Len(a interface{}) int

len 返回集合对象的长度,对象可以是数组(array),切片(slice),映射(map),字符串(string)或通道(channel) Example: ``` a = [1, 2, 3] println(len(a)) // 3 ```

func Lshr

func Lshr(a, b interface{}) interface{}

Lshr returns a << b

func Make

func Make(typ yaksepc.GoTyper, args ...int) interface{}

make 创建切片(slice), 映射(map), 通道(chan) ! 已弃用,可以使用 make 语句代替

func Map

func Map(key, elem interface{}) interface{}

Map returns map[key]elem

func MapFrom

func MapFrom(args ...interface{}) interface{}

mapFrom 根据传入的键值对初始化映射(map) ! 已弃用,可以使用 map 初始化语句代替 Example: ``` m = mapFrom("a", 1, "b", 2) // {"a": 1, "b": 2} ```

func MapInit

func MapInit(args ...interface{}) interface{}

MapInit creates a map object from `mapInit(mapType, member1, val1, ...)`.

func MapOf

func MapOf(key, val interface{}) interface{}

mapOf 返回指定类型的映射类型,可用于 mkmap 中 ! 已弃用,可以使用 make 语句代替 Example: ``` m = mkmap(mapOf("string", "var")) // map[string]any ```

func Max

func Max(args ...interface{}) (max interface{})

max 返回多个值中的最大值,这只对数字类型有效 Example: ``` max(1,2,3,4,5) // 5 max(1,1.1,2.2,3.3,4.4,5.5) // 5.5 ```

func Min

func Min(args ...interface{}) (min interface{})

min 返回多个值中的最小值,这只对数字类型有效 Example: ``` min(1,2,3,4,5) // 1 min(1,1.1,2.2,3.3,4.4,5.5) // 1 ```

func Mkmap

func Mkmap(typ interface{}, n ...int) interface{}

mkmap 创建指定类型的映射(map) ! 已弃用,可以使用 make 语句代替 Example: ``` m = mkmap("string:var") // map[string]any ```

func Mkslice

func Mkslice(typ interface{}, args ...interface{}) interface{}

mkslice 创建指定类型的切片(slice) ! 已弃用,可以使用 make 语句代替 Example: ``` a = mkslice("var") // []any ```

func Mod

func Mod(a, b interface{}) interface{}

Mod returns a%b or return fmt.Sprintf(a,b...)

func Mul

func Mul(a, b interface{}) interface{}

Mul returns a*b

func NE

func NE(a, b interface{}) interface{}

NE returns a != b

func Neg

func Neg(a interface{}) interface{}

Neg returns -a

func Not

func Not(a interface{}) interface{}

Not returns !a

func Panic

func Panic(v interface{})

panic 崩溃并打印错误信息 Example: ``` panic("something happened") ```

func Panicf

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

panicf 崩溃并根据格式化打印错误信息 Example: ``` panicf("something happened: %v", err) ```

func Quo

func Quo(a, b interface{}) interface{}

Quo returns a/b

func Rshr

func Rshr(a, b interface{}) interface{}

Rshr returns a >> b

func Set

func Set(m interface{}, args ...interface{})

set 设置一个对象的值,对象可以是数组(array),切片(slice),映射(map)或结构体(struct)或结构体引用(ptr) ! 已弃用,可以使用初始化语句或赋值语句代替 Example: ``` a = make([]int, 3) set(a, 0, 100, 1, 200, 2, 300) // a = [100, 200, 300] ```

func SetIndex

func SetIndex(m, key, v interface{})

SetIndex sets a (index, value) pair to an object. object can be a slice, an array, a map or a user-defined class.

func Slice

func Slice(elem interface{}) interface{}

Slice returns []T

func SliceFrom

func SliceFrom(args ...interface{}) interface{}

sliceFrom 根据传入的键值对初始化切片(slice) ! 已弃用,可以使用 slice 初始化语句代替 Example: ``` a = sliceFrom(1, 2, 3) // [1, 2, 3] ```

func SliceFromTy

func SliceFromTy(args ...interface{}) interface{}

SliceFromTy creates a slice from `[]T{a1, a2, ...}`.

func SliceOf

func SliceOf(typ interface{}) interface{}

sliceOf 返回指定类型的切片类型,可用于 mkslice 中 ! 已弃用,可以使用 make 语句代替 Example: ``` m = mkslice(sliceOf("var")) // []any ```

func String

func String(a interface{}) string

String returns string(a)

func StringEx

func StringEx(a interface{}, verbose string) string

func StructInit

func StructInit(args ...interface{}) interface{}

StructInit creates a struct object from `structInit(structType, member1, val1, ...)`.

func Sub

func Sub(a, b interface{}) interface{}

Sub returns a-b

func SubSlice

func SubSlice(a, i, j interface{}) interface{}

sub 返回数组或切片的子切片 ! 已弃用,可以使用切片语句代替 Example: ``` a = [1, 2, 3, 4, 5] b = sub(a, 1, 3) // [2, 3] 相当于 a[1:3] ```

func Ternary

func Ternary(condation, a, b interface{}) interface{}

Ternary

func Uint

func Uint(a interface{}) uint

Uint returns uint(a)

func Uint16

func Uint16(a interface{}) uint16

Uint16 returns uint16(a)

func Uint32

func Uint32(a interface{}) uint32

Uint32 returns uint32(a)

func Uint64

func Uint64(a interface{}) uint64

Uint64 returns uint64(a)

func Uint8

func Uint8(a interface{}) byte

Uint8 returns uint8(a)

func Xor

func Xor(a, b interface{}) interface{}

Xor returns a ^ b

Types

This section is empty.

Jump to

Keyboard shortcuts

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