set /a x=1,y=2,z=x + y

May 20, 2008
12,167
133
Syracuse, NY, USA
Is there any chance that you'd include this capability of CMD?

v:\> set /a x=1,y=2,z=x + y
3
v:\> echo %x% %y% %z%
1 2 3
--
- Vince
 
Jun 3, 2008
137
3
Temecula, CA
Looks like yet another silly CMD extension. Why not just write

V:\> set /a x=1 & set /a y=2 & set /a z=x + y

One little interesting thing I noticed. With Vince's requested syntax,
CMD only displays the 3, while with mine (which also works for both TCC
and CMD), it displays 123 for CMD, and 1 / 2 / 3 (with the slashes to
indicate line breaks). Slightly different output. OK, so my request
isn't 100% compatible between TCC and CMD either. Well, at least it
works!

________________________________

From: vefatica [mailto:]
Sent: Thursday, June 05, 2008 9:57 AM
To: Mickey Ferguson
Subject: [Support-t-139] set /a x=1,y=2,z=x + y

Is there any chance that you'd include this capability of CMD?

v:\> set /a x=1,y=2,z=x + y
3
v:\> echo %x% %y% %z%
1 2 3
--
- Vince
 
May 20, 2008
12,167
133
Syracuse, NY, USA
On Thu, 05 Jun 2008 12:35:58 -0500, you wrote:


>Looks like yet another silly CMD extension. Why not just write
>
>V:\> set /a x=1 & set /a y=2 & set /a z=x + y

Silly?

set /a x=1,y=2,z=x + y

is a lot easier to write and, I'd bet, a lot faster to execute.
--
- Vince
 
Jun 3, 2008
137
3
Temecula, CA
I highly doubt it makes any execution time difference. With a .bat file
you have to load each line separately (interpreted), so you can run into
performance issues when they are on separate lines. But we've got the
'&' now, with everything all on one line, so that's not an issue. In
today's world of extremely fast processors, I can't see how it could
make much of a difference, unless you're talking about many millions of
executions, and even then, only a little bit. I might be wrong about my
assessment, but I would be very surprised if I was.

And besides, if you really have a process that is so extensive, is the
command processor a good choice for language? Performance should almost
never be a priority consideration for batch processing, as long as the
difference is not significant.

________________________________

From: vefatica [mailto:]
Sent: Thursday, June 05, 2008 10:43 AM
To: Mickey Ferguson
Subject: RE: [Support-t-139] set /a x=1,y=2,z=x + y

On Thu, 05 Jun 2008 12:35:58 -0500, you wrote:


Quote:

>Looks like yet another silly CMD extension. Why not just write
>
>V:\> set /a x=1 & set /a y=2 & set /a z=x + y
Silly?

set /a x=1,y=2,z=x + y

is a lot easier to write and, I'd bet, a lot faster to execute.
--
- Vince
 
May 20, 2008
12,167
133
Syracuse, NY, USA
On Thu, 05 Jun 2008 13:13:57 -0500, you wrote:


>I highly doubt it makes any execution time difference. With a .bat file
>you have to load each line separately (interpreted), so you can run into
>performance issues when they are on separate lines. But we've got the
>'&' now, with everything all on one line, so that's not an issue.

But three commands have to be parsed instead of one.

Anyway, according to the help, "SET /A is included for compatibility with
CMD.EXE".
--
- Vince
 
May 20, 2008
12,167
133
Syracuse, NY, USA
On Thu, 05 Jun 2008 15:36:38 -0500, you wrote:


>> Is there any chance that you'd include this capability of CMD?
>>
>> v:\> set /a x=1,y=2,z=x + y


>Why? (Unless you're trying to obfuscate your code, I don't see any
>reason for it.)

It's perfectly clear to me. It's easier to write than the alternative and I'd
bet it is (or could be) faster. Those are the reasons I ask for it. I don't
care a whit about CMD compatibility (but it's occasionally a good lever).
--
- Vince
 

rconn

Administrator
Staff member
May 14, 2008
12,556
167
vefatica wrote:


> Quote:
> >> Is there any chance that you'd include this capability of CMD?
> >>
> >> v:\> set /a x=1,y=2,z=x + y
>
> Quote:
> >Why? (Unless you're trying to obfuscate your code, I don't see any
> >reason for it.)
>
> It's perfectly clear to me. It's easier to write than the alternative
> and I'd
> bet it is (or could be) faster. Those are the reasons I ask for it.

It won't be any faster, and it certainly won't be any easier to read.

This is undocumented behavior for CMD -- have you seen anybody using
this in CMD code?

It also would break existing code, as it means you would not be able to
use thousands separators in your argument -- for example, try this in in
TCC and CMD:

set /a x=123,456

For some of our non-US users, replace "would not be able to use
thousands separators" with "would not be able to use decimal separators".

All in all, I think it's poorly-thought-out syntax (assuming it's a CMD
feature, and not a bug!), and I don't intend to change TCC.

Rex Conn
JP Software
 
May 20, 2008
603
0
Sammamish, WA
>> >> Is there any chance that you'd include this capability of CMD?
>> >> v:\> set /a x=1,y=2,z=x + y


> This is undocumented behavior for CMD -- have you seen anybody using
> this in CMD code?

First, I am not arguing for a change, nor even its frequency of usage,
just quibbling about the "undocumented" bit. From CMD, I typed HELP
SET and in the order of precedence, it shows "," as "expression
separator" which I interpret as documenting the behavior.

I saw several things in CMD's SET help that I'd never seen before.

--
2008 Fridays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Saturday.
Measure wealth by the things you have for which you would not take money.
 
May 20, 2008
12,167
133
Syracuse, NY, USA
On Thu, 05 Jun 2008 16:49:42 -0500, you wrote:


>This is undocumented behavior for CMD -- have you seen anybody using
>this in CMD code?

It is documented, albeit, scantily.

SET /A expression
, - expression separator
--
- Vince
 
May 20, 2008
12,167
133
Syracuse, NY, USA
On Thu, 05 Jun 2008 16:49:42 -0500, you wrote:


>It won't be any faster, and it certainly won't be any easier to read.

Here's a simple-minded version called SETA (even works).

INT WINAPI SETA ( WCHAR * psz )
{
WCHAR *p = wcstok(psz, L","), szCmd[8192];
while ( p )
{
Sprintf(szCmd, L"/A %s", p);
Set_Cmd(szCmd);
p = wcstok(NULL, L",");
}
return 0;
}

It seems to be about 20-25% faster. See the test below.

v:\> type seta.btm
echo Using SET /A:
timer /q
do i=1 to 10000
set /a x=1 & set /a y=2 & set /a z=x + y
enddo
timer
echo Using SET /A on separate lines
timer /q
do i=1 to 10000
set /a x=1
set /a y=2
set /a z=x + y
enddo
timer
echo Using SETA:
timer /q
do i=1 to 10000
seta x=1, y=2, z=x + y
enddo
timer

v:\> seta.btm
Using SET /A:
Timer 1 off: 20:21:42 Elapsed: 0:00:04.27
Using SET /A on separate lines
Timer 1 off: 20:21:46 Elapsed: 0:00:04.57
Using SETA:
Timer 1 off: 20:21:50 Elapsed: 0:00:03.39

--
- Vince
 

Similar threads

Replies
4
Views
2K