Variants
Wednesday, December 21st, 2005A variant variable can change its type dynamically while the program is running. A variant object can be an integer at one point in the program, switch to a string at a different part of the program, and then change to a real value at a later time. Many very high level language systems use a dynamic type system (i.e., variant objects) to reduce the overall complexity of the program; indeed, proponents of many very high level languages insist that the use of a dynamic typing system is one of the reasons you can write complex programs in so few lines.
kdb and kdb+ use variant types, and this allows type overloading of operators e.g.
q)f:{x+y} /define a function that adds 2 arguments
q)f[10;1.0] / pass an int and float,returns a float
11f
q)f[10;10] / pass an int and int,returns an int
20
q)f[10 20 30;10] / pass an int vector and int,returns an int vector
20 30 40
q)f[10 20 30;60 70 80.0] / pass an int vector and a float vector, returns a float vector
70 90 110f