tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,18 @@
set globalVar "This is a global variable"
namespace eval nsA {
variable varInA "This is a variable in nsA"
}
namespace eval nsB {
variable varInB "This is a variable in nsB"
proc showOff {varname} {
set localVar "This is a local variable"
global globalVar
variable varInB
namespace upvar ::nsA varInA varInA
puts "variable $varname holds \"[set $varname]\""
}
}
nsB::showOff globalVar
nsB::showOff varInA
nsB::showOff varInB
nsB::showOff localVar

View file

@ -0,0 +1,11 @@
oo::class create example {
# Note that this is otherwise syntactically the same as a local variable
variable objVar
constructor {} {
set objVar "This is an object variable"
}
method showOff {} {
puts "variable objVar holds \"$objVar\""
}
}
[example new] showOff

View file

@ -0,0 +1,4 @@
proc decr {varName {decrement 1}} {
upvar 1 $varName var
incr var [expr {-$decrement}]
}

View file

@ -0,0 +1,3 @@
proc semival args {
uplevel 1 [join $args ";"]
}

View file

@ -0,0 +1,15 @@
proc loop {varName from to body} {
upvar 1 $varName var
for {set var $from} {$var <= $to} {incr var} {
uplevel 1 $body
}
}
loop x 1 10 {
puts "x is now $x"
if {$x == 5} {
puts "breaking out..."
break
}
}
puts "done"