Plan for a new library of script utility functions

From OHRRPGCE-Wiki
Jump to navigation Jump to search

Arrays, floating point, and so on will be added to HS in the future. Once we have these common data structures, we should also supply various functions that operate on them, as you would expect in the standard libraries of a modern high level language.

Incidentally, this is is a really strong argument for switching to Python or something else well developed instead.

Considerations[edit]

Naming issues[edit]

The names used below are likely to be placeholders. However I'm somewhat concerned about further namespace pollution, since many of the suggested names are very short and common. We could even put these in a namespace!

Functional vs. imperative[edit]

No mention on whether these functions modify their arguments or return new objects - too lazy to argue about this at the moment. (The Mad Cacti: Personally I think functional programming is awesomer than object orientated programming, so I suggest that.)

Other[edit]

Multi-dimensional arrays are mentioned, but aren't really in the plan, they may or may not actually happen (as opposed to arrays of arrays).

Functions[edit]

Extend this list!

Pseudo-random numbers[edit]

http://docs.python.org/library/random.html

  • random (min = 0.0, max = 1.0)
random should be extended so that if one or more of the arguments is a floating point, it returns a floating point number
  • permute (a)
randomly permute the elements of an array.
  • random array (min, max, dim1, ...)
Return a (possible multidimensional) array of specified size with random contents
  • random from (a)
Returns a random element from an array 'a'

Arrays[edit]

http://docs.python.org/library/itertools.html http://docs.python.org/library/stdtypes.html#set-types-set-frozenset http://docs.python.org/library/stdtypes.html#mapping-types-dict

Where 'a' is a (possibly multidimensional) array or dictionary

  • length (a)
  • range (min, max)
Returns an array filled with the integers from min to max. Should max be excluded?
  • sort (a, reverse = false, uniques only = false)
  • reverse (a)
  • remove duplicates (a)
Remove duplicated items from an unsorted array.
  • sum (a)
  • product (a)
  • find (a, x)
Find x in a (if a is a dictionary, this is a search for a value). Return an lvalue?
  • average (a)
  • map (a, scriptid)
:)

Floating point numbers[edit]

Where below 'f' is an integer or floating point number or an array of floating point numbers/integers

  • floor (f)
  • ceiling (f)
  • round (f) or integer (f)

and so on

Strings[edit]

http://docs.python.org/library/strings.html http://docs.python.org/library/stdtypes.html#string-methods

See Also[edit]