RosettaCodeData/Task/Extend-your-language/Tcl/extend-your-language-1.tcl
2023-07-01 13:44:08 -04:00

15 lines
499 B
Tcl

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
}
}