Skip to content

Instantly share code, notes, and snippets.

@muspellsson
Created November 10, 2014 10:01
Show Gist options
  • Save muspellsson/8883c02c8551810bfaaf to your computer and use it in GitHub Desktop.
Save muspellsson/8883c02c8551810bfaaf to your computer and use it in GitHub Desktop.
proc invariant {var {expression ""} {msg "Illegal value"}} {
uplevel trace variable $var w \
\[list invariant_check \{$expression\} \{$msg\}]
}
proc invariant_check {expression msg v1 v2 mode} {
if {$expression == ""} {
error "Cannot modify!"
}
if {![uplevel expr \{$expression\}]} {
error $msg
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment