Skip to main content

Tcl and OTcl Tutorial For NS2 variables and arrays

Tcl and OTcl Tutorial For NS2 variables and arrays



Variables and arrays

Defining a variable in Tcl is very simple:
set var1 1
set var2 "Tcl Variable 2"
The variables can be referenced by prefixing the variable name with a $. For example to print the above variables, we can use
puts "var1=$var1, var2=$var2"
Any situation in which you require that the value of the variable be used is one in which the $ prefix should be added to the variable name. In some situations, it is necessary to use the variable name directly. For example
incr var1
can be used to increment var1. I guess you can think of it as the difference between call-by-reference and call-by-value: in the former case you use the variable name on its own, while in the latter you prefix it with a $.An alternative is to assign the results of a function to a variable. This can be done as follows:
set var3 [expr 5*10]
This sets the variable var3 to the result of calling the expr function with the parameter 5*10. The expr function attempts to evaluate the supplied parameter to derive a value. Tcl interprets the square brackets as delimiters for a nested command: it attempts to execute the command inside the square brackets and assigns the result to var3 in this case. The returned value will be 50. Hence, the value 50 will be assigned to var3.In Tcl all variables are represented internally as strings. Whether that string can be viewed as an integer or a floating point number only matters when you use a function that requires numeric arguments.
Tcl also supports arrays. These are very useful in ns for storing, say, nodes. Tcl supports arrays that can be indexed by simple numeric arguments, as is standard in most languages, but Tcl also supports arrays that can be indexed by arbitrary strings. It is not necessary to declare the size of the array in advance. Here, two example of arrays are given
set n(0) [$ns node]
set n(1) [$ns node]
set opts(bottlenecklinkrate) 1Mb
set opts(ECN) "on"
In the first example the array is called n and the index is numeric. In the second, the array is called opts and the index is non-numeric.

download file now

Popular posts from this blog

Takenoko I LOVE This Game!

Takenoko I LOVE This Game! My Husband bought me the Collectors Edition of Takenoko and when I first saw it, I immediately thought: ok this is definitely a girly game made to entertain young children. However, Takenoko turned out to be a fantastic game! Ive even put it in my �top five" games list. Its a game meant for 2-4 players and is recommended for ages 13 and up, yet my Husband and I had no problems playing this with our kids who are 11 and 12. The box says it plays in about 45 minutes, but weve found most games take about 60 if playing with 4 people --youll be having so much fun, time wont matter anyways! The backstory of Takenoko is written in a comic book style inside the rulebook. Its a super cute game where a Chinese Emperor whom has a large garden --grows a wide selection of bamboo plants, maintained by his Gardener. However the Emperor has now received a present - a large panda bear which he lets roam around in his garden. Unfortunately the panda has quite the appetit...

Toukiden Kiwami English Patch ISO Free Download PPSSPP Setting

Toukiden Kiwami English Patch ISO Free Download PPSSPP Setting Toukiden Kiwami is a semi-sequel follow-up to the demon battling game Toukiden. This package introduces more Slayers, Oni, storylines, and chapters, serving as a robust expansion of the largely successful Toukiden: The Age of Demons. � IGN Screen Shots: File Name:  Toukiden Kiwami Publisher: Tecmo Koei Developer: Omega Force Genre: Action Image Format: .ISO File Size: 1.6 GB Best PPSSPP Setting Of  Toukiden Kiwami Gold Version.1.3.0.1 wait for 5 seconds & click the skip ad You may click the link below to download your file Download Instruction: Click download button and wait for 5 Seconds   and click the Skip Ad   at the right top corner and the file is in another website  G o o g l e   Drive Link . Just click the download and the file will be download. Sometimes the file goes to ads website to get the exact downloading file back to clicking on download now and again rep...