difference between bcc'ed and eval'ed regexp
the [regexp] compiler does option completion, but the normal command does not?
% regexp -n FoO dogfood
bad switch "-n": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --
while evaluating {regexp -n FoO dogfood}
% proc a {} {regexp -n FoO dogfood}; a
1
The completion feature is tested in regexpComp.test: 21.6-7 and 24.6-7
Hmmm ... this seems to show that regexp itself is not consistent with standard Tcl option behavior, which is to allow uniq abbrs of options. Indeed, Tcl_RegexpObjCmd uses TCL_EXACT for getopts, whereas the compile cmd does a strcmp of len >= 2. It seems like it would be consistent to correct tclCompCmds.c to enforce the full -nocase, as regexp has behaved that way since 8.0, even if most Tcl commands allow abbr opts. Agreed?
Still the same in 8.6, 9.0 and 9.1: TclCompileRegexpCmd() accepts any prefix of -nocase of at least 2 characters, while Tcl_RegexpObjCmd() requires the full option name. string compare, string equal, string map, string match, switch, lsearch and lsort all accept abbreviations of -nocase.
Proposed fix in branch regexp-nocase-abbrev: instead of making the compiler exact, the command also accepts abbreviations of -nocase. This breaks nothing, since it only turns errors into successes. Other options still need their full names. Tests regexp-30.1 to 30.3.
Actually, I have a problem with some options within the same command being abbreviatable and others not. No other Tcl command does that.
So, my proposal variant is: [e93dfd305ea29e3b].
In this specific case, I don't see any negative side-effect doing that.
In general we should not advocate using abbreviated options, since it may cause incompatibilities if later options are added. But in manual typing in a shell, there's no harm, therefore many commands (especially when preceded with a minus-sign) allow that. We should - in my opinion - do the same here.
That is a decision for you. I only considered variants for
-nocase: either make it never abbreviated (simpler, but breaking,
and inconsistent with -nocase in other commands), or always
abbreviated. Making all options abbreviatable is a wider change.
Note that with all options abbreviatable some prefixes are ambiguous:
-a (-all, -about) and
-i/-in (-indices, -inline)
in regexp, and -l/-li/-lin
in both commands. -line can only be used in full, and
-a would mean -all in regsub but be an
error in regexp. -n is unique in both.
Two related mismatches between compiled code and the command, where the
compiler accepts an abbreviation that the command rejects as ambiguous:
[1ae976e237] (clock clicks -mi, new in 9.1) and [8ab06e31e3]
(self n).
Merged to [trunk] and core-9-0-branch.
Merge to 8.6 still to be done