Posted to tcl by Setok at Mon Nov 07 12:46:56 GMT 2022view raw

  1. proc typedVar {var assert} {
  2. uplevel [list trace add variable $var write [list apply {{expr var key op} {
  3. set val [uplevel set $var]
  4. if $expr {
  5. } else {
  6. error "Variable value does not match spec"
  7. }
  8. }} $assert]]
  9. }
  10.  
  11. # Example: typedVar b {[string is integer]}; set b 242; set b "front"