%

expr integer modulus operator

expr { $a % $b }

If "a == b % c", then "a == b - (b / c) * c"
Alternatively: (x / y) * y == x - (x % y)

Also the first character of substitution specifiers in format, bind, scan, clock, ...


jima A question that perhaps should be placed elsewhere:

Recently reading Aspect Support Class for TclOO I found the following bit of code

method DefineAspect args {
 set opts [dict merge {
  -name {}
  -condition 1 -before {} -after {}
  -variable ASPECT__result -trap {}
 } $args]
 if {[dict get $opts -trap] eq ""} {
  set script {
   if {[lindex [self target] 0] eq "::oo::object"} {
    return [next {*}$args]
   }
   if {%1$s} {
    %2$s
    set %4$s [next {*}$args]
    %3$s
    return [set %4$s]
   } else {
   return [next {*}$args]
  }
 }
...

Where I assume %1$s , %2$s et cetera are "script parts" of an invocation like:

aspect -before {
 my variable ValueCache
 set key [self target],$args
 if {[info exist ValueCache($key)]} {
  return $ValueCache($key)
 }
} -variable result -after {
 set ValueCache($key) $result
}

The thing I don't get is where is the magic of %1$s and terms alike defined.

Is this something that follows standard rules of tcl?

Or is it just something parsed inside the TclOO package?

RS: Well, if you look at the very next line, it is

        set script [format $script \
                [dict get $opts -condition] \
                [dict get $opts -before] \
                [dict get $opts -after] \
                [list [dict get $opts -variable]] \
                [list [dict get $opts -trap]]]

so the % things are placeholders for items to get substituted into the script.

DKF: Yes, the % is also used in format to indicate a substitution point, though I admit that code uses the somewhat-unusual XPG positional format specifiers because there are substitutions that I don't always need or sometimes need more than once. They're also used in bind (and if you want to put a format statement or expression inside a binding script, it's better to use a helper procedure. Really) and some clock subcommands too (notably clock format and 8.5's clock scan).


AMG: Any reason why % can't be extended to work with real numbers? % is easier to type than fmod().