Taken from tclcl see http://www-mash.cs.berkeley.edu/ns. Slightly hacked to free it from some of tclcl.