Professional Documents
Culture Documents
programming
languages
There are two type of languages used to write the
Frontend
TCL/Otcl
Backend
C/C++
Backend
Frontend
In order to use ns2, we must first understand the
TCL
Tcl is a string-based command language.
A command does something for you, like output a
Variables
The set command is used to assign a value to a
variable.
It takes two arguments:
OPERATORS
- + !
* / %
<< >>
eq ne in ni
compare two strings for equality (eq) or inequality (ne). and two
operators for checking if astring is contained in a list (in) or not (ni)
New command
OTcl allows you to define your own commands,
Example
% proc triple arg1 { return [expr $arg1 * 3] }
% triple 9
27
% set t [triple 9]
27
% puts $t
27
Example
o justdoit 10 20
o set b to 20, and leave C to its default
Control structures
Tcl comes with a number of built in commands for
control structures.
if statements
different kinds of loops.
Ex(if)
set x 5
i f { $x == 1 } {
puts TRue
} el se {
puts not True
}
Ex(else if )
i f { $x == 1 } {
puts f i r s t
} e l s e i f { $x == 2 } {
puts second
} el se {
puts thi r d
}
while
set value 1
set fact 2
while { $ fact <= 5 } {
set value [ expr $value +$ fact ]
incr fact
}
puts $value
Ex(for)
set sum 0
for { set i 0 } { $ i < 10 } { incr i } {
set sum [ expr $sum + $ i ]
}
puts $sum
File Access
Tcl provides several methods to read from and write
to files on disk.
Gets command
puts command
Ns2 objects