
Section 2
:
TSP Programming Fundamentals
Series 3700 System Switch/Multimeter Reference Manual
2-24
Document Number: 3700S-901-01 Rev. A / August 2007
Variables and types
TSL has six basic types; nil, boolean, number, string, function, and table. TSL is a dynamically
typed language, which means variables do not need to be declared as a specific type. Instead,
variables assume a type when a value is assigned to them. Therefore, each value carries its
own type. If a variable has not been assigned a value, the variable defaults to the type nil. All
numbers are real numbers. There is no distinction between integers and floating-point numbers
in TSL.
var = nil
var is nil.
var = 1.0
var is now a number.
var = 0.3E-12
var is still a number.
var = 7
var is still a number.
var = "Hello world!"
var is now a string.
var = "I said, Hello world!"
var is still a string.
var = function(a, b) return(a+b) end
var is now a function that adds two
numbers.
var = {1, 2., 3.00e0}
var is now a table (in other words, an
array) with three initialized members.
Nil is a type with a single value, nil, whose main property is to be different from any other value.
Global variables have a nil value by default
—before a first assignment—and you can assign nil
to a global variable to delete it. TSL uses nil as a kind of non-value to represent the absence of
a useful value.
Operators
Arithmetic operators:
+ ............................................................................................................ (addition)
- ........................................................................................................ (subtraction)
*..................................................................................................... (multiplication)
/ ............................................................................................................. (division)
- ............................................................................................................(negation)
Relational operators:
< .......................................................................................................... (less than)
> ..................................................................................................... (greater than)
<= .......................................................................................... (less than or equal)
>= ...................................................................................... (greater than or equal)