7.6.4 Singleton lists

Prev Up Next Page 194 of 800 Search internet

A 'singleton' is a vector of length one. Singletons are useful for representing bytes.

As an example, in Unicode UTF-8, the character 'b' is represented by the byte 98 and by the singleton !"b" = 98 + 256 = 354. In general, byte x is represented by the singleton x+256.

The vt2vector* ( x ) function converts a text x to a singleton list:

vt2vector* ( !"ab" :: !"cd" ) == << !"a" ,, !"b" ,, !"c" ,, !"d" >>

There also is a vector2vector* ( x ) function which converts a vector x to a singleton list, but there is little use for it since one can just as well use vt2vector* ( x ). Do not even expect a reward in cpu-time for using vector2vector* ( x ).

Singleton lists have two nice properties: First, they are easy to process using list processing functions. Second, they are themselves vector trees, so one can also use vector tree functions on them. They have the drawback that they take up more memory than vectors.

Prev Up Next Page 194 of 800 Search logiweb.eu

Copyright © 2010 Klaus Grue, GRD-2010-01-05