Information about [Threads]
Random [Diatribes]
----
My [Friends]
Information about [Tcl]
Random [Scripts]
Random [Links]
Feel free to contact me about this website at mailto:wiki@rkeene.org
Random [Demonstrations]
Information about interesting [Current Projects]
Information about [Random Number Generation]
Information about [Roy Keene]
My [Scratchpad]
'''What you will find here'''
** [Reimplementing the If Statement in Tcl] **
#! /usr/bin/tclsh
# Delete the "if" command
rename if ""
# Make our own.
proc if args {
set result [uplevel 1 [list expr [lindex $args 0]]]
switch -- $result {
"1" {
uplevel 1 [lindex $args 1]
}
default {
switch -- [lindex $args 2] {
"else" {
uplevel 1 [lindex $args 3]
}
}
}
}
}
# Test it
if {1} { puts "Test" }
if {0} { puts "No Test" }
if {1} { puts "Joe" } else { puts "Bob" }
if {0} { puts "Joe" } else { puts "Bob" }
foreach joe [list bob joe sally] {
if {$joe == "joe"} {
puts "Joe = joe !"
} else {
puts "Joe = $joe."
}
}