Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Why are these so screwy?

May
12,846
164
Below, I really wanted _DOY 0-padded to 3 digits and the rest to 2 digits. But that did absolutely nothing.

Code:
v:\> function pad `%@format[0%@IF["%1"=="_doy",3,2],%%%1]`

v:\> do t in /L _month _day _hour _minute _second _doy ( echo %t = %@pad[%t] )
_month = 6
_day = 8
_hour = 21
_minute = 59
_second = 4
_doy = 160

So for emphasis I tried larger numbers. And I get screwy results ... _day and _hour padded to 3 digits, _doy padded to 6 digits, and the others not padded at all (and none padded to the requested 8 or 7 digits).

Code:
v:\> function pad `%@format[0%@IF["%1"=="_doy",8,7],%%%1]`

v:\> do t in /L _month _day _hour _minute _second _doy ( echo %t = %@pad[%t] )
_month = 6
_day = 008
_hour = 022
_minute = 3
_second = 2
_doy = 000160

Why is it so screwy?
 
Here's another attempt to do the same thing. It misbehaves differently. The @IF works correctly, giving the correct number of characters. But "%%%1" is not evaluated correctly (whereas, with @FORMAT, "%%%1" was evaluated correctly but the formatting was not correct).

Code:
v:\> function zp `%@right[%@if["%1"=="_doy",3,2],00%%%1]`

v:\> do t in /L _month _day _hour _minute _second _doy ( echo %t = %@zp[%t] )
_month = th
_day = ay
_hour = ur
_minute = te
_second = nd
_doy = doy

It's interesting that the following slight variation does work.

Code:
v:\> function zp `%@right[%@if["%1"=="doy",3,2],00%_%1]`

v:\> do t in /L month day hour minute second doy ( echo %t = %@zp[%t] )
month = 06
day = 09
hour = 10
minute = 35
second = 02
doy = 161
 
In short, these two (somewhat similar) attempts to do the same thing both fail, but they fail differently. The first expands "%%%1" (apparently properly) but doesn't honor @FORMAT's format specification. The second does the reverse; it honors @RIGHT's count specification but doesn't expand "%%%1" properly.

Code:
v:\> function pad `%@format[0%@IF["%1"=="_doy",3,2],%%%1]`

v:\> do t in /L _month _day _hour _minute _second _doy ( echo %t = %@pad[%t] )
_month = 6
_day = 8
_hour = 21
_minute = 59
_second = 4
_doy = 160


Code:
v:\> function zp `%@right[%@if["%1"=="_doy",3,2],00%%%1]`

v:\> do t in /L _month _day _hour _minute _second _doy ( echo %t = %@zp[%t] )
_month = th
_day = ay
_hour = ur
_minute = te
_second = nd
_doy = doy
 
Your pad function is calling @format with the arguments 02,%_month - so you're trying to format the literal string %_month, not the value of the internal variable %_month.

Your zp function is calling @format with the arguments 2,00%_month.
Is there a generic way to both of them?
 
The debugger allows you to single-step through functions so you can see exactly what TCC is doing.
I don't know what you mean. How do I step through the evaluation of a user-defined variable function and where do I look to see what's going on?
 
Back
Top