DWIM parser?

May 31, 2008
Running the batch file at the bottom, I expected to see output
() ()
Instead I got
(Xcon) ()
WAD, DWIM or something else? I wasn't able to ascertain if the help file does say that %[name] and %name% are equivalent forms, I thought they are under all circumstances.
@echo off
for %i in (X) (gosub LBL "%i")
set icon=ABC
echo (%icon%)
unset icon
echo (%icon%) (%[icon])
TCC LE 13.03.38 Windows 7 [Version 6.1.7601]
The whole GOSUB is within the scope of the FOR, thus "%icon" is interpreted as in a FOR - %i becomes X (its only value set by FOR), %icon becomes Xcon... Goes back to the days of COMMAND.COM...
So that's one more reason for getting in the habit of using %[name] instead of %name or %name%. %[name] seems to give consistent results under all circumstances.
Or it's one more reason not to use single-character FOR variables.
That's a hard to habit to break. I bet if I had the TCC source code in front of me, in it I'd probably find something similar to the following...

for (int i=0;i<10;i++) {
  // some code here
No doubt, but in C++ there's no difference between one-letter and multicharacter variable names.
Nor in any other compiled language, AFAIK. Even among interpreted languages this one stands alone - I know of no other case but COMMAND.COM and its supersets, and even those only when declared in a FOR command, that single out single-character variable names for unique treatment. For TCC this behavior is thoroughly documented in the description of the FOR command, in the "Other Notes" section.