6.1 Instantiating objects

A list of all of Pyxplot’s built-in object types can be found in the types module, which contains the object prototypes for each type. Its contents are as follows:

pyxplot> print types
module {
  boolean       : $<$data type: boolean$>$
  color         : $<$data type: color$>$
  date          : $<$data type: date$>$
  dictionary    : $<$data type: dictionary$>$
  exception     : $<$data type: exception$>$
  fileHandle    : $<$data type: fileHandle$>$
  function      : $<$data type: function$>$
  instance      : $<$data type: instance$>$
  list          : $<$data type: list$>$
  matrix        : $<$data type: matrix$>$
  module        : $<$data type: module$>$
  null          : $<$data type: null$>$
  number        : $<$data type: number$>$
  string        : $<$data type: string$>$
  type          : $<$data type: type$>$
  vector        : $<$data type: vector$>$
 }

These object prototypes can be called like functions to produce an instance of each data type. Each prototype can take various different kinds of argument; for example, the number prototype can take a number, boolean or a string from which to create a number. For example:

pyxplot> types.number()
0
pyxplot> types.number(true)
1
pyxplot> types.number(27)
27
pyxplot> types.number("1.2e39")
1.2e+39

Full documentation of the types of inputs supported by each prototype are listed in the Reference Manual, in Section 12.11.

In many cases there are much more succinct ways of creating objects of each type. For example, lists can be creating by enclosing a comma-separated list of elements in square brackets:

pyxplot> print [10,colors.green,"bottles"]
[10, cmyk(1,0,1,0), "bottles"]

Dictionaries can be can be creating by enclosing key–value pairs in curly brackets:

pyxplot> s = {"name":"Sophie", "nationality":"British"}
pyxplot> s["hometown"] = "Lode"
pyxplot> s["birthYear"] = 1957