std.util

Provides miscellaneous utility functions.

  • Author: Edward Jones
  • Date: 2021-09-17

Source file

argmax

Computes the argmax of a function over a set of values.

  • Param f: The function to compute
  • Param vs: a list of values to test

Returns: The argmax of f over vs, that is the v in vs which maximises f(v), also returns the value of f(v)

argmax = (f, vs) -> ...

argmin

Computes the argmin of a function over a set of values.

  • Param f: The function to compute
  • Param vs: a list of values to test

Returns: The argmin of f over vs, that is the v in vs which minimises f(v), also returns the value of f(v)

argmin = (f, vs) -> ...

bool_to_int

Converts a boolean value to an integer.

  • Param b: The value to check

Returns: true if b is considered true otherwise 0

bool_to_int = (b) -> ...

char_at

Returns a string representing the character at a given index.

  • Param i: The index to obtain
  • Param s: The string from which to extract

Returns: A string which contains just the i-th character of s

char_at = (i, s) -> ...

chars

Creates a coroutine which yields the characters of a string.

  • Param s: The string from which to yield

Returns: A coroutine which yields strings of length 1 which represent the individual characters of s

chars = (s) -> ...

elem

Returns whether a value is an element of a list.

  • Param v: A value to check membership
  • Param vs: A list of values to search

Returns: true if v is a value if vs, otherwise false

elem = (v, vs) -> ...

eq

Recursively computes the equality of two values.

  • Param a: A value to check
  • Param b: A value to check

Returns: true if a and b are equal, otherwise false

eq = (a,b) -> ...

extend

Computes the result of extending a given list by other lists (pure).

  • Param xs: A list to extend
  • Param ...: Further lists

Returns: A list which is the concatenation of the lists passed, in the order passed.

extend = (xs, ...) -> ...

is_list

Returns whether a given value represents a list.

  • Param l: The value to check

Returns: true if l is a list, otherwise false

is_list = (l) -> ...

non_nil

Returns whether a value is not nil.

  • Param v: Value to check

Returns: true if v is not nil otherwise false

non_nil = (v) -> ...

on_iter_wrap

Wrap a given function so that it is only run on a particular typesetting iteration.

  • Param f: The function to wrap

Returns: A function which takes a number n and the parameters to f which when called will only execute f if the current typesetting loop iteration is equal to n

on_iter_wrap = (f) -> (n, ...) -> ...

sorted

Sort a list and then return it (impure).

  • Param t: A list to sort
  • Param ...: Further parameters to table.sort

Returns: t, having been sorted in place

sorted = (t, ...) -> ...