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

May 20, 2008
11,378
98
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
121
1
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
11,378
98
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
121
1
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
11,378
98
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
11,378
98
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,340
149
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
11,378
98
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
11,378
98
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
Thread starter Title Forum Replies Date
V Set path permanently from within TCC? Support 3
S Debugger keeps breaking with no break point set. Support 1
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
R How to? Set default application in a special folder Support 4
A How to? Set up SMTP password in TCC-RT Support 1
vefatica WAD More SET /A woes Support 4
vefatica SET /A and multidimensional array. Support 1
M How to set Path variable for non-executable file extensions in 4DOS Support 8
D Need to set Take Command font size when switching to high DPI display Support 0
P "Set" command behavior - a bug? Support 3
M How to? Set the ribbon titles to mixed case Support 1
X How to set %_INIREAD result to variable Support 5
M WAD Set statements in () causes problems Support 8
M How to? How to set a default TITLE for newly opened tab? Support 2
M Fixed Set "VAR=VAL" format causes problems Support 12
vefatica SET /A var=expression=digits Support 3
cxxl Set encoding for batch file Support 4
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2
vefatica SET /A var\=...? Support 10
dcantor Documentation SET /T: missing from heading Support 0
fpefpe Documentation Set /v Support 4
vefatica What's SET /Z? Support 1
R Fixed set /r has stopped working in build 35 Support 4
BeechComer Debugger: how to set %1 variable? Support 3
fpefpe How to? Global variable set /v Support 4
fpefpe Documentation Can the title line of tcmd be set? Support 4
J How to set working directory Support 10
Jay Sage Failure of ACTIVATE to Set a Window Position Support 3
rps Fixed Win "set /p" not working in V17 build 53 Support 3
vefatica SET /A "var%=N", TCC vs. CMD Support 0
J Set environment variable from stdout of command Support 3
B How to? Pre-set _tcfolder on startup when Folders is set Auto-Hide Support 6
Dan Glynhampton Fixed @version "force" flag not working, and unable to set separator Support 3
R WAD /= size ranges not set correctly Support 5
S How to? Set the timestamp of ZIP command built archive to match latest member Support 8
Mordachai Help! How to set parameters for script I'm debugging?! Support 6
Roedy SET= Support 2
A How to? Set up a log file for all command output Support 3
M Fixed character set in dir/copy Support 3
Phileosophos Fixed TakeCommand exits upon "set [" command Support 14
R How to set comspec to point to cmd.exe? Support 5
S WAD SET problem - array element initialization Support 11
C Wildcard expansion in FOR set Support 27
vefatica SET question Support 16
T Set 1% then Echo 1% Support 9
S SET /A question; HELP nits Support 8
noahcoad copy /w to FTP does not set time stamp Support 1
M A request for a new feature for the "set" command... Support 5
cgunhouse Accessing variables set using SET /U or SET /S Support 3
D Force For to treat set of values as text, not files Support 3

Similar threads