Professional Documents
Culture Documents
1. Try out the following Tcl commands and interpret the output :
proc SetPositive {variable value } {
upvar $variable myvar
if {$value < 0} {
set myvar [expr {-$value}]
} else {
set myvar $value
}
return $myvar
}
SetPositive x 5
SetPositive y -5
set x 1
set y 2
for {set i 0} {$i < 5} {incr i} {
set a($i) $i;
}
puts "\ntesting unsetting a simple variable"
# Confirm that x exists.
existence x
# Unset x
unset x
puts "x has been unset"
# Confirm that x no longer exists.
existence x
2. Try out the following Tcl commands and interpret the output :
# Matches
string match f* foo
# Matches
string match f?? foo
# Doesn't match
string match f foo
3. Try out the following Tcl Commands and interpret the output :
puts "\"[string range $string 5 10]\" are characters between the 5'th and
10'th"
4. Try out the following Tcl commands and interpret the output :
if {$first != 0} {
} else {
# If "/" is not the last character in $path, report the last word.
# else, remove the last "/", and find the next to last "/", and
incr last
} else {
incr last;
if {$comparison >= 0} {
} else {
5. Try out the following Tcl Commands and interpret the output :
puts "$labels"
puts "$price1"
puts "$price2"
puts "$price3"
puts "$price4"