tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
18
Task/Scope-modifiers/Tcl/scope-modifiers-1.tcl
Normal file
18
Task/Scope-modifiers/Tcl/scope-modifiers-1.tcl
Normal 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
|
||||
11
Task/Scope-modifiers/Tcl/scope-modifiers-2.tcl
Normal file
11
Task/Scope-modifiers/Tcl/scope-modifiers-2.tcl
Normal 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
|
||||
4
Task/Scope-modifiers/Tcl/scope-modifiers-3.tcl
Normal file
4
Task/Scope-modifiers/Tcl/scope-modifiers-3.tcl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
proc decr {varName {decrement 1}} {
|
||||
upvar 1 $varName var
|
||||
incr var [expr {-$decrement}]
|
||||
}
|
||||
3
Task/Scope-modifiers/Tcl/scope-modifiers-4.tcl
Normal file
3
Task/Scope-modifiers/Tcl/scope-modifiers-4.tcl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
proc semival args {
|
||||
uplevel 1 [join $args ";"]
|
||||
}
|
||||
15
Task/Scope-modifiers/Tcl/scope-modifiers-5.tcl
Normal file
15
Task/Scope-modifiers/Tcl/scope-modifiers-5.tcl
Normal 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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue