Yazoo ---> Online Help Docs ---> Yazoo scripting ---> Working with variables

Primitive variables

Most of the variables we have encountered so far are the `primitive' variables that store data: as a number, a string, or a `block' (sequence of bytes). Only numeric variables can be operated on by the arithmetic operators. Variables defined as byte blocks can be sized to arbitrary numbers of bytes, although they cannot subsequently be re-sized. Strings boast dynamic storage: each time data is copied into them they are automatically resized appropriately.

The numeric types are: ubyte and sbyte (for unsigned and signed bytes), ushort and sshort (short-integer words), ulong and slong (long words, machine-dependent but usually 4 or 8 bytes), and single and double for single- and double-precision floating-point numbers. These are also listed in Table 1, which also gives the range of values each type can store. As mentioned before, variables are defined by the define `::' operator, and multiple variables of the same type can be defined on the same line.


    height :: time :: g :: double
   

The variables are defined in the order left-to-right, so in this case height is the first floating-point double to be defined. All primitive numeric and block variables begin life initialized to zero, and all strings are initialized a no-string state (distinct from the zero-character string). To change the value stored by a variable, use the equate operator `='.


    time = height = 0
    g = -9.8
    units = "m/s^2"
   

The type name for defining byte blocks is block, and the type for strings is, logically, string. The block type actually takes one parameter: the number of bytes to allocate for the variable. For example, the syntax for defining a 3-byte triplet variable is:


    triplet :: block 3
   

Byte blocks are not useful very often and the author has toyed with the idea of taking them out altogether. The scenario that made him hesitate is the case of reading data with some fixed-width field via read_string(). In this case strings may rescale incorrectly, and read_string() might attempt an inappropriate string-to-number conversion if a numeric type is used instead.


Prev: Working with variables   Next: Composite variables


Last update: July 28, 2013

Get Yazoo scripting language at SourceForge.net. Fast, secure and Free Open Source software downloads