std

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package std provides a number of basic WDTE functions.

The functions provided by this package are slightly different from those in many of the standard library's packages in that they are intended to be directly inserted into the top-level scope, rather than imported. They provide basic functionality, such as addition and subtraction, as well as some more language-specific functionality, such as the ability to check the type of a value.

Index

Constants

View Source
const (
	// True is a WDTE function with the following signature:
	//
	//    true
	//
	// As you can probably guess, it returns a boolean true.
	True wdte.Bool = true

	// False is a WDTE function with the following signature:
	//
	//    false
	//
	// Returns a boolean false. This is rarely necessary as most
	// built-in functionality considers any value other than a boolean
	// true to be false, but it's provided for completeness.
	False wdte.Bool = false
)

Variables

View Source
var (
	// Import provides a simple importer that imports registered
	// modules.
	Import = wdte.ImportFunc(stdImporter)
)
View Source
var Scope = wdte.S().Map(map[wdte.ID]wdte.Func{
	"+": wdte.GoFunc(Plus),
	"-": wdte.GoFunc(Minus),
	"*": wdte.GoFunc(Times),
	"/": wdte.GoFunc(Div),
	"%": wdte.GoFunc(Mod),

	"==":    wdte.GoFunc(Equals),
	"<":     wdte.GoFunc(Less),
	">":     wdte.GoFunc(Greater),
	"<=":    wdte.GoFunc(LessEqual),
	">=":    wdte.GoFunc(GreaterEqual),
	"true":  True,
	"false": False,
	"&&":    wdte.GoFunc(And),
	"||":    wdte.GoFunc(Or),
	"!":     wdte.GoFunc(Not),

	"len":     wdte.GoFunc(Len),
	"at":      wdte.GoFunc(At),
	"known":   wdte.GoFunc(Known),
	"set":     wdte.GoFunc(Set),
	"reflect": wdte.GoFunc(Reflect),

	"memo": wdte.GoFunc(ModMemo),
	"rev":  wdte.GoFunc(ModRev),
})

Scope is a scope containing the functions in this package.

This scope is primarily useful for bootstrapping an environment for running scripts in. To use it, simply pass a frame containing it or a subscope of it to a function call. In many cases, a client can simply call F to obtain such a frame.

Functions

func And

func And(frame wdte.Frame, args ...wdte.Func) wdte.Func

And is a WDTE function with the following signature:

&& ...

Returns true if all of its arguments are true.

func At

func At(frame wdte.Frame, args ...wdte.Func) wdte.Func

At is a WDTE function with the following signatures:

at a i
(at i) a

Returns the ith index of a. a is assumed to implement wdte.Atter.

func Div

func Div(frame wdte.Frame, args ...wdte.Func) wdte.Func

Div is a WDTE function with the following signatures:

/ a b
(/ b) a

Returns a divided by b.

func Equals

func Equals(frame wdte.Frame, args ...wdte.Func) wdte.Func

Equals is a WDTE function with the following signatures:

== a b
(== b) a

Returns true if a equals b. If a implements wdte.Comparer, the equality check is done using that implementation. If a does not but b does, b's implementation is used. If neither does, a direct Go equality check is used.

func F

func F() wdte.Frame

F returns a top-level frame that has S as its scope.

func Greater

func Greater(frame wdte.Frame, args ...wdte.Func) wdte.Func

Greater is a WDTE function with the following signatures:

> a b
(> b) a

Returns true if a is greater than b. Comparison rules are the same as those used for Equals, with the exception that the argument used must not only implement wdte.Comparer but that that implementation must support ordering.

func GreaterEqual

func GreaterEqual(frame wdte.Frame, args ...wdte.Func) wdte.Func

GreaterEqual is a WDTE function with the following signatures:

>= a b
(>= b) a

Returns true if a is greater than or equal to b. Comparison rules are the same as those used for Equals, with the exception that the argument used must not only implement wdte.Comparer but that that implementation must support ordering.

func Known added in v0.2.2

func Known(frame wdte.Frame, args ...wdte.Func) wdte.Func

Known is a WDTE function with the following signature:

known scope

Returns an array containing known identifiers in the given scope sorted alphabetically.

func Len

func Len(frame wdte.Frame, args ...wdte.Func) wdte.Func

Len is a WDTE function with the following signature:

len a

Returns the length of a if a implements wdte.Lenner, or false if it doesn't.

func Less

func Less(frame wdte.Frame, args ...wdte.Func) wdte.Func

Less is a WDTE function with the following signatures:

< a b
(< b) a

Returns true if a is less than b. Comparison rules are the same as those used for Equals, with the exception that the argument used must not only implement wdte.Comparer but that that implementation must support ordering.

func LessEqual

func LessEqual(frame wdte.Frame, args ...wdte.Func) wdte.Func

LessEqual is a WDTE function with the following signatures:

<= a b
(<= b) a

Returns true if a is less than or equal to b. Comparison rules are the same as those used for Equals, with the exception that the argument used must not only implement wdte.Comparer but that that implementation must support ordering.

func Minus

func Minus(frame wdte.Frame, args ...wdte.Func) wdte.Func

Minus is a WDTE with the following signatures:

  • a b (- b) a

Returns a minus b.

func Mod

func Mod(frame wdte.Frame, args ...wdte.Func) wdte.Func

Mod is a WDTE function with the following signatures:

% a b
(% b) a

Returns a mod b.

func ModMemo added in v0.12.0

func ModMemo(frame wdte.Frame, args ...wdte.Func) wdte.Func

func ModRev added in v0.12.0

func ModRev(frame wdte.Frame, args ...wdte.Func) wdte.Func

func Not

func Not(frame wdte.Frame, args ...wdte.Func) wdte.Func

Not is a WDTE function with the following signature:

! a

Returns true if a is not true or false if a is not true.

func Or

func Or(frame wdte.Frame, args ...wdte.Func) wdte.Func

Or is a WDTE function with the following signature:

|| ...

Returns true if any of its arguments are true.

func Plus

func Plus(frame wdte.Frame, args ...wdte.Func) wdte.Func

Plus is a WDTE function with the following signatures:

  • a ... (+ a) ...

Returns the sum of a and the rest of its arguments.

func Reflect added in v0.4.2

func Reflect(frame wdte.Frame, args ...wdte.Func) wdte.Func

Reflect is a WDTE function with the following signature:

reflect v type
(reflect type) v

It provides a simple wrapper around wdte.Reflect, checking underlying type compatability.

func Register

func Register(name string, module *wdte.Scope)

Register registers a module for importing by Import.

func Set added in v0.8.0

func Set(frame wdte.Frame, args ...wdte.Func) wdte.Func

Set is a WDTE function with the following signatures:

set con key val
(set val) con key
(set key val) con

Set uses con's implementation of Setter to produce a new value from con with a key-val mapping applied to it. For example,

set [1; 2; 3] 1 5

returns a new Array containing [1; 5; 3].

func Times

func Times(frame wdte.Frame, args ...wdte.Func) wdte.Func

Times is a WDTE function with the following signatures:

  • a ... (* a) ...

Returns the product of a and its other arguments.

Types

type Memo added in v0.12.0

type Memo struct {
	Func wdte.Func
	Args []wdte.ID
	// contains filtered or unexported fields
}

A Memo wraps another function, caching the results of calls with the same arguments.

func (*Memo) Call added in v0.12.0

func (m *Memo) Call(frame wdte.Frame, args ...wdte.Func) wdte.Func

Directories

Path Synopsis
Package all is a convenience package that imports the entire standard library, thus registering it with std.Import.
Package all is a convenience package that imports the entire standard library, thus registering it with std.Import.
Package arrays contains functions for manipulating arrays.
Package arrays contains functions for manipulating arrays.
io
Package io contains WDTE functions for dealing with files and other types of data streams.
Package io contains WDTE functions for dealing with files and other types of data streams.
file
Package file provides functions for dealing with files.
Package file provides functions for dealing with files.
Package math contains wdte.Funcs for performing mathematical operations.
Package math contains wdte.Funcs for performing mathematical operations.
Package rand provides functions for generating and dealing with random numbers.
Package rand provides functions for generating and dealing with random numbers.
Package stream provides WDTE functions for manipulating streams of data.
Package stream provides WDTE functions for manipulating streams of data.
Package strings contains functions for dealing with strings.
Package strings contains functions for dealing with strings.

Jump to

Keyboard shortcuts

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