proc integer args {
foreach arg $args {
uplevel 1 "trace var $arg w {incr $arg 0 ;#}"
}
}
% integer i
% set i x
can't set "i": expected integer but got "x"proc List args {
foreach arg $args {
uplevel 1 "trace var $arg w {llength \[set $arg\] ;#}"
}
}
% List foo
% set foo {bar "grill}
can't set "foo": unmatched open quote in listproc number args {
foreach arg $args {
uplevel 1 "trace var $arg w {expr 0+$$arg ;#}"
}
}
% number p
% set p 5
5
% set p 5.4
5.4
% set p hello
can't set "p": syntax error in expression "0+hello": variable references require preceding $This error message isn't as clear as the others - maybe one should catch it and replace with a clearer. But the smallness of the traces would get lost in this process...JCG: The Simple Library uses that mechanism on steroids, so that the error message is pretty explanatory:
% ::Simple::Variable::configure -monitortype true 1 % ::Simple::Variable::create ::foo -type integer % set ::foo 23 23 % set ::foo kk can't set "::foo": invalid value "kk" for variable "::foo" of type "integer"
See also

