Logiweb(TM)

7.6.2 Vectors

Prev Up Next Page 192 of 800 Search internet


We refer to integers which represent strings as 'byte vectors' or just 'vectors'. As an example, 5996503394 is a vector because it represents the string "bake".

We refer to integers that represent strings as vectors regardless of whether or not they respect the conventions for Logiweb text.

Formally, to be a vector, an integer x must be positive and must satisfy integer-length ( x ) mod 8 = 1

The following operations are suited for operations on vectors:

vector ( x )
Convert the integer x to a list of bytes using little endian base 256. Then chop off the last byte, add a one-byte, and convert back to an integer. Hence, when applied to a vector, this function returns x. When applied to an integer which is not a vector, it returns x with the end byte 'corrected'.
vector-norm ( x )
Return x unmodified if it represents a vector. Return true otherwise.
vector-empty ( x )
True if x represents the empty vector.
vector-index ( x , i )
Convert x to a sequence of bytes, then return byte i (where byte zero is the first byte of the sequence)
vector-suffix ( x , b )
Convert x to a sequence of bytes, discard bytes before byte b (where byte zero is the first byte), then convert back to a vector.
vector-prefix ( x , e )
Convert x to a sequence of bytes, discard byte e and the bytes following it, then convert back to a vector.
vector-subseq ( x , b , e )
Convert x to a sequence of bytes, discard byte e and the bytes following it, then discard bytes before byte b, then convert back to a vector.
vector-length ( x )
Return the number of bytes in the vector x.

All functions above accept arbitrary integers x rather than just vectors. When applied to an integer which is not a vector, the functions operate on vector ( x ) rather than x.

The Logiweb Abstract Machine (lgwam) supports two, distinct representations for integers: One which can be used for arbitrary integers and one which can only be used for representing vectors. Vector operations tend to be faster when applied to the latter representation.

One cannot see from the outside which representation lgwam uses when. The two representations are near-identical. They only differ in a single bit which is set for integers which are known to represent vectors. The functions above except vector-empty, vector-index, and vector-length return vectors.

Prev Up Next Page 192 of 800 Search logiweb.eu

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