12.11 The types module

The types module contains prototype objects for each of Pyxplot’s data types. Each may be called like a function to create a new object of the specified type:

types.boolean(...)
The types.boolean(...) prototype takes any of the following combinations of arguments:

  • none – returns false.

  • any object – returns false for zero, an empty string, a null object, or an empty data structure. Otherwise returns true.

types.color(...)
The types.color(...) prototype takes any of the following combinations of arguments:

  • none – returns black.

  • a color – returns a copy of that color.

  • a number – returns the color at the specified position in the present palette.

types.date(...)
The types.date(...) prototype takes any of the following combinations of arguments:

  • none – returns the current time.

  • a date – returns a copy of that date.

types.dictionary(...)
The types.dictionary(...) prototype takes any of the following combinations of arguments:

  • none – returns an empty dictionary.

  • a dictionary – returns a deep copy of the supplied dictionary.

types.exception(...)
The types.exception(...) prototype takes any of the following combinations of arguments:

  • a string – returns an exception type with the specified name.

  • an exception – returns a copy of the supplied exception type.

types.fileHandle(...)
The types.fileHandle(...) prototype takes any of the following combinations of arguments:

  • none – returns a file handle of a temporary file.

  • a file handle – returns a copy of the supplied file handle.

types.function(...)
The types.function(...) prototype takes any of the following combinations of arguments:

  • Cannot be called. Functions should be created using the syntax f(x)=...

types.instance(...)
The types.instance(...) prototype takes any of the following combinations of arguments:

  • none – returns an empty module.

  • a module or instance – returns a deep copy of the supplied module or instance.

types.list(...)
The types.list(...) prototype takes any of the following combinations of arguments:

  • none – returns an empty list.

  • a list – returns a deep copy of the supplied list.

  • a vector – returns a list representation of the supplied vector.

  • a list of arguments returns its arguments as a list.

types.matrix(...)
The types.matrix(...) prototype takes any of the following combinations of arguments:

  • none – returns a one-by-one zero matrix.

  • a pair of numbers – returns a zero matrix of the specified dimensions. The first number is the number of rows, and the second the number of columns.

  • a matrix – returns a copy of the supplied matrix.

  • one or more vectors, or a list of vectors – converts the supplied vector(s) into the columns of a new matrix object.

  • one or more lists, or a list of lists – converts the supplied list(s) into the rows of a new matrix object, providing all the elements are numerical and have matching units.

types.module(...)
The types.module(...) prototype takes any of the following combinations of arguments:

  • none – returns an empty module.

  • a module – returns a deep copy of the supplied module.

types.null(...)
The types.null(...) prototype takes any of the following combinations of arguments:

  • none – returns a null object.

types.number(...)
The types.number(...) prototype takes any of the following combinations of arguments:

  • none – returns zero.

  • a number – returns that number.

  • a boolean – returns zero or one.

  • a string – converts the string to a number if it is in a valid format, or returns an error if not.

types.string(...)
The types.string(...) prototype takes any of the following combinations of arguments:

  • none – returns an empty string.

  • any object – returns a string representation of the object.

types.type(...)
The types.type(...) prototype takes any of the following combinations of arguments:

  • Cannot be called. New data types cannot be created except by instantiating modules.

types.vector(...)
The types.vector(...) prototype takes any of the following combinations of arguments:

  • none – returns the vector [0].

  • a number – returns a zero vector with the specified number of dimensions.

  • a vector – returns a copy of the supplied vector.

  • a list – converts the supplied list to a vector, providing all of its elements are numerical and have consistent units.

  • a list of arguments returns its arguments as a vector, providing they are all numerical and have consistent units.