China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-31 17:08
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » It can also be calculated without using variable delay [setlocal enableDelayedExpansion] View 4,769 Replies 49
Floor 16 Posted 2008-06-25 21:15 ·  法国
高级用户
★★
Credits 783
Posts 268
Joined 2006-12-26 17:18
19-year member
UID 74627
Gender Male
Status Offline
Originally posted by qzwqzw at 2008-6-25 02:09 PM:
Everyone has been talking for a long time
Don't you all feel that we are discussing the problem around a very non-typical example?
Does no one know that set /a has the default delay effect?

The example of the landlord is completely unnecessary to change...


What if it is written in one line?
菩提本无树,明镜亦非台,本来无一物,何处惹尘埃.
Floor 17 Posted 2008-06-25 21:20 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Very tasteless idea. The code pursues simplicity and clarity rather than being short and strange.
Floor 18 Posted 2008-06-25 21:20 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 195
Posts 93
Joined 2006-10-28 08:20
19-year member
UID 68626
Gender Male
Status Offline
Originally posted by qzwqzw at 2008-6-25 09:09 PM:
You've been talking for a long time,
Don't you all think you're discussing the problem around a very non-typical example?
Does no one know that set /a has the default delay effect?

The example of the building owner is completely unnecessary to change...

Brother seems to have insufficient understanding of what delay variables are. Similarly, the variable will naturally take effect after the for loop ends.
Apply an example above without set/a

@echo off
for /f %%a in ('dir/b') do (
set ww=%%a
)
echo %ww%
pause

It can be seen that the final variable %ww% will be assigned the last value
Floor 19 Posted 2008-06-25 21:30 ·  法国
高级用户
★★
Credits 783
Posts 268
Joined 2006-12-26 17:18
19-year member
UID 74627
Gender Male
Status Offline
Bland idea
Code pursues simplicity and clarity
Not short and strange

Then, isn't Lao Da's signature made worthless by what you said...

[ Last edited by PPdos on 2008-6-25 at 02:32 PM ]
菩提本无树,明镜亦非台,本来无一物,何处惹尘埃.
Floor 20 Posted 2008-06-25 21:30 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 195
Posts 93
Joined 2006-10-28 08:20
19-year member
UID 68626
Gender Male
Status Offline
Originally posted by qzwqzw at 2008-6-25 09:15 PM:
Brother metoo, the remarks in post 9 are a bit thoughtless.

In the DOS era without variable delay,
it is also possible to "assign continuously / directly obtain intermediate links"

This only requires making some small changes to the :num_add section that is called...

Indeed. This format can be used..
Some of my code was also under-considered. I'm glad this forum can have such an atmosphere^ ^
Floor 21 Posted 2008-06-25 21:31 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Brother metoo may have misquoted. I was refuting your remarks on the 15th floor.

My statement on the 13th floor was to prove that the code of the thread starter is redundant. It seems there is no problem.

First, I am familiar with variable delay. The "delayed variable" is the first time I've seen it.

What problem are you trying to illustrate with the example on the 18th floor?

Any variable should naturally take effect as the last one after being "continuously assigned"? There's nothing to discuss about this.

[ Last edited by qzwqzw on 2008-6-25 at 11:11 PM ]
Floor 22 Posted 2008-06-25 21:45 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
The weight of the content of the signature is greater than its appearance. The helplessness and openness revealed in it are what I very much appreciate. If there were no those finishing-off explanatory words, I would only regard it as something passing by. But many people are confused in the technical maze by that strange structure and a post of explanation by willsort, and instead lose the most precious inner part. Don't think that in the place where technology is discussed, one should get stuck in the technical details. After all, the discussion and development of technology are constantly bringing forth new things, while the feeling of the heart and the experience of life are often extremely precious.
Floor 23 Posted 2008-06-25 21:54 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 195
Posts 93
Joined 2006-10-28 08:20
19-year member
UID 68626
Gender Male
Status Offline
Actually, the original poster's statement is correct - -!
Then brother ppdos's simplification is actually wrong. It cannot replace the delayed variable, but is just the final product after simple consecutive assignments, and then I explained his that - -!

Actually
Whether it's called variable delay/delayed variable or whatever (of course 99% is that I called it wrong. Even a stubborn person has to be stubborn)
The purpose of its existence is to get each step of the variable changes obtained by set in the for loop and then process them.
When using set in for application, delayed variable is necessary. And using call is to put set in the outer circle of the loop command, which is a process of continuously calling sub - processes to achieve an effect similar to delayed variable.

Also, the signature of "Helpless" is not consecutive assignment. Note that the set/p parameter is an interactive command. This place may be the most essential part of this signature.

[ Last edited by metoo on 2008-6-25 at 09:56 PM ]
Floor 24 Posted 2008-06-25 21:58 ·  法国
高级用户
★★
Credits 783
Posts 268
Joined 2006-12-26 17:18
19-year member
UID 74627
Gender Male
Status Offline
Everyone didn't say the building owner was wrong~~?

I just think the building owner wrote it a bit long and simplified it a bit

Whether it's wrong or not is still a matter of personal opinion
菩提本无树,明镜亦非台,本来无一物,何处惹尘埃.
Floor 25 Posted 2008-06-25 22:16 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
20-year member
UID 59307
Status Offline
I didn't expect so many people to discuss.

Just like what qzwqzw on floor 15 of page 1 said, changing it like this can display the middle one.

Also, "metoo" is quite funny, "stubborn dead duck"

@echo off
for /f %%a in ('dir/b') do call :num_add file_num
echo There are %file_num% files (folders) in the directory.
pause
goto :eof

:num_add
 set/a %1+=1
 :: Added the next line
 echo %file_num%
 goto :eof


[ Last edited by wxcute on 2008-6-25 at 10:25 PM ]
┌───────┐
├→学习→实践→┤
└───────┘
Floor 26 Posted 2008-06-25 22:21 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
First of all, the LZ's statement is definitely correct. Calculations can certainly be done without variable delays (even in a for loop). Of course, the "calculation" here is very vague, leading to everyone having their own understanding. The implied meaning here by the LZ is that call can be used instead of delay because call appears in his code. Secondly, the LZ's code is also correct, with correct syntax and achieving the desired effect. What I want to show is that the LZ's code cannot prove the implied meaning in his view because I can achieve the same purpose in a non-call and non-delay way, so there is no way to explain the significance of call replacing delay. -------------------------------------------------------- From the first reply of ppdos, it is known that he understands the default delay effect of set /a I mentioned in building 14, but just didn't connect it with the LZ's statement as a problem. Simplification itself is not a problem, and I just think that condensing into one line of code is a bit redundant. One can also find evidence to prove the view that call can replace delay. (for /f %i in ('dir /b') do set /a n+=1 >nul)&call echo There are %n% files(folders) under the directory can be replaced by (for /f %i in ('dir /b') do set /a n+=1 >nul)&echo There are!n! files(folders) under the directory. This shows that when encountering variable delay problems in the connected statements, call can be used to replace, while metoo looks into the for, of course, not seeing anything valuable. -------------------------------------------------------- As for the signature of Wunaaihe, that's really off-topic. I only remember those few lines of words now, and the code has long been forgotten completely, and I don't bother to dig it out again, and just let it be whether it's continuous assignment or not. [ Last edited by qzwqzw on 2008-6-25 at 10:28 PM ]
Floor 27 Posted 2008-06-25 22:27 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 195
Posts 93
Joined 2006-10-28 08:20
19-year member
UID 68626
Gender Male
Status Offline
The author's method is correct.. But that simplified version can't replace the delay variable.. I have realized this mistake.. Say, the moderator's case is a special situation, not continuously assigning values.. Using the interactive way of set/p.. That call is not used in this way.. I imitated his signature to write a p version
@echo off
set tt=One, two, three, four, five, go up the mountain to fight tigers, the tiger is not at home, go home to eat sweet potatoes. ——metoo counterfeit version
for /l %%i in (0,1,36)do (
call call set/p= %%%%tt:~%%i,1%%%%<nul&ping/n 1 127.1>nul
)


According to the above statement, then what kind of explanation is my call call?

[ Last edited by metoo on 2008-6-25 at 10:40 PM ]
Floor 28 Posted 2008-06-25 22:30 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
20-year member
UID 59307
Status Offline
Actually, I'm also just a newbie, and I didn't think that deeply.

I'm just used to using %, and it's a bit uncomfortable to replace % with!, and also writing "setlocal enableDelayedExpansion" is quite tedious. I have a bad memory, and it took me some time to remember it.
┌───────┐
├→学习→实践→┤
└───────┘
Floor 29 Posted 2008-06-25 22:33 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 195
Posts 93
Joined 2006-10-28 08:20
19-year member
UID 68626
Gender Male
Status Offline
Originally posted by wxcute at 2008-6-25 10:30 PM:
Actually, I'm also a newbie, not thinking that deeply.

Just used to using %, it's a bit uncomfortable to use! instead of %, and also writing "setlocal enableDelayedExpansion" is quite tedious. I have a bad memory, it took me some time to remember.

I'm also a newbie, to be honest, I can't remember this stuff now. I set up a shortcut input! in editplus!
Floor 30 Posted 2008-06-25 22:38 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
It gets a bit chaotic when there are too many people.
Plus there are a few who like to edit posts.
After looking at it for a while, I just can't follow the train of thought.

Now let's sort it out.
ppdos initially just wanted to simplify the LZ's code.
Then it was proposed that Wunaaihe's signature was a refutation of my statement "short and weird is not可取".

metoo wanted to explain the meaning of "continuous assignment" of variable delay and use that to prove its irreplaceable nature.
Later it was mentioned that Wunaaihe's signature didn't use variable delay because it didn't use "continuous assignment".

I initially just wanted to say that the LZ's code couldn't prove the LZ's viewpoint.
Now I want to extend the LZ's viewpoint —

for+call can replace for+delay, in any case.

Everyone is welcome to come up with examples to refute my viewpoint.
By the way, it's also a sort-out of my own programming ideas and code skills.
Forum Jump: