Timer issue

samintz

Scott Mintz
May 20, 2008
1,421
13
Solon, OH, USA
I was testing Vince's timing issue with arrays and noticed an odd issue with the TIMER command.
Code:
setarray /f a[100]
timer do i=0 to 99 (set a[%i]=0)
TCC: Invalid array argument (out of bounds) "a[100]"
...
TCC: Invalid array argument (out of bounds) "a[100]"
Timer 1 off: 14:51:15  Elapsed: 0:00:00.055
I had to double the %'s - set a[%%i]=0 - in order to get rid of the TCC error.

If I change the command to be timer & do ... & timer off then it works as I expected it to.

Why do I need to double the %'s ?

-Scott
 
May 20, 2008
10,621
81
Syracuse, NY, USA
I don't know the details, but that version of TIMER doesn't get parsed like many other things. Here's another.

Code:
v:\> (echo foo & echo bar)
foo
bar

v:\> timer (echo foo & echo bar)
Timer 1 on: 15:07:26
More?
Fix that one thus:

Code:
v:\> timer (echo foo ^& echo bar)
Timer 1 on: 15:08:15
foo
bar
Timer 1 off: 15:08:15  Elapsed: 0:00:00.002
 

rconn

Administrator
Staff member
May 14, 2008
11,925
133
I was testing Vince's timing issue with arrays and noticed an odd issue with the TIMER command.
Code:
setarray /f a[100]
timer do i=0 to 99 (set a[%i]=0)
TCC: Invalid array argument (out of bounds) "a[100]"
...
TCC: Invalid array argument (out of bounds) "a[100]"
Timer 1 off: 14:51:15  Elapsed: 0:00:00.055
I had to double the %'s - set a[%%i]=0 - in order to get rid of the TCC error.

If I change the command to be timer & do ... & timer off then it works as I expected it to.

Why do I need to double the %'s ?

-Scott
Because the command line is being parsed twice - once for TIMER, and then again for the DO.

The TIMER argument is intended for simple commands; it's not well suited for handling loops or command groups.
 

rconn

Administrator
Staff member
May 14, 2008
11,925
133
I don't know the details, but that version of TIMER doesn't get parsed like many other things. Here's another.

Code:
v:\> (echo foo & echo bar)
foo
bar

v:\> timer (echo foo & echo bar)
Timer 1 on: 15:07:26
More?
Fix that one thus:

Code:
v:\> timer (echo foo ^& echo bar)
Timer 1 on: 15:08:15
foo
bar
Timer 1 off: 15:08:15  Elapsed: 0:00:00.002
That would require a custom parser for TIMER on the (remote) chance that you're passing it a command group. Otherwise, when the parser is evaluating the TIMER line, it will break the line at the first &.

I don't think you'd be happy if the parser suddenly decided to evaluate possible command groups inside everything:

echo This is a line (and this isn't a command group)