Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Extend-your-language/Tcl/extend-your-language-1.tcl
Normal file
15
Task/Extend-your-language/Tcl/extend-your-language-1.tcl
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
proc if2 {cond1 cond2 bothTrueBody firstTrueBody secondTrueBody bothFalseBody} {
|
||||
# Must evaluate both conditions, and should do so in order
|
||||
set c1 [uplevel 1 [list expr $cond1]
|
||||
set c2 [uplevel 1 [list expr $cond2]
|
||||
# Now use that to decide what to do
|
||||
if {$c1 && $c2} {
|
||||
uplevel 1 $bothTrueBody
|
||||
} elseif {$c1 && !$c2} {
|
||||
uplevel 1 $firstTrueBody
|
||||
} elseif {$c2 && !$c1} {
|
||||
uplevel 1 $secondTrueBody
|
||||
} else {
|
||||
uplevel 1 $bothFalseBody
|
||||
}
|
||||
}
|
||||
9
Task/Extend-your-language/Tcl/extend-your-language-2.tcl
Normal file
9
Task/Extend-your-language/Tcl/extend-your-language-2.tcl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
if2 {1 > 0} {"grill" in {foo bar boo}} {
|
||||
puts "1 and 2"
|
||||
} {
|
||||
puts "1 but not 2"
|
||||
} {
|
||||
puts "2 but not 1"
|
||||
} {
|
||||
puts "neither 1 nor 2"
|
||||
}
|
||||
8
Task/Extend-your-language/Tcl/extend-your-language-3.tcl
Normal file
8
Task/Extend-your-language/Tcl/extend-your-language-3.tcl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
proc if2 {cond1 cond2 body00 body01 body10 body11} {
|
||||
# Must evaluate both conditions, and should do so in order
|
||||
# Extra negations ensure boolean interpretation
|
||||
set c1 [expr {![uplevel 1 [list expr $cond1]]}]
|
||||
set c2 [expr {![uplevel 1 [list expr $cond2]]}]
|
||||
# Use those values to pick the script to evaluate
|
||||
uplevel 1 [set body$c1$c2]
|
||||
}
|
||||
6
Task/Extend-your-language/Tcl/extend-your-language-4.tcl
Normal file
6
Task/Extend-your-language/Tcl/extend-your-language-4.tcl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
proc loop {varName lowerBound upperBound body} {
|
||||
upvar 1 $varName var
|
||||
for {set var $lowerBound} {$var <= $upperBound} {incr var} {
|
||||
uplevel 1 $body
|
||||
}
|
||||
}
|
||||
8
Task/Extend-your-language/Tcl/extend-your-language-5.tcl
Normal file
8
Task/Extend-your-language/Tcl/extend-your-language-5.tcl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
proc timestables {M N} {
|
||||
loop i 1 $M {
|
||||
loop j 1 $N {
|
||||
puts "$i x $j = [expr {$i * $j}]"
|
||||
}
|
||||
}
|
||||
}
|
||||
timestables 3 3
|
||||
Loading…
Add table
Add a link
Reference in a new issue