mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
FroggieDaFrog #222988 11/07/10 03:55 PM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
(Note: I'm avoiding the discussion of "switch" in this reply since that suggestion was a thread hijack and completely tangential to the OP-- there are many threads on that suggestion already)

Khaled has never removed an identifier since *parmsN, so your concern is a little overstated. In fact, $* is one of the oldest identifiers mIRC has and is used by countless scripts, so it's not going anywhere.

I think this suggestion in particular is an exercise in form, not function, and misses the point. The classical benefit of a foreach() construct is to allow enumeration via a unified interface for any object/data. Specifically, it allows user-types to be enumerated in the same way builtin-types would be, which is kind of useless in a non-typed language to begin with. Moreover, if you have to pass contextual switches based on the data type, you lose the unified interface and all you're left with is a construct that saves a few keystrokes. Is this really just about vanity?

People need to stop trying to suggest <favourite control flow construct> from <favourite language>, this thread is getting a little ridiculous. Do you really think Khaled is going to add for, foreach at the same time? Maybe if everyone agreed on a single syntax, Khaled might take these suggestions more seriously... but I think this is indicative of the real problem at hand. It shows that this suggestion is nothing more than a stylistic one, which means it's not going to end here. Once Khaled implements for/foreach someone will come along and ask for do/while or "until" loops. How many different syntaxes for looping do you need?

Let's look at this another way: "while" can do everything mentioned in this thread in roughly the same number of bytes. Why don't we have a discussion about what's wrong with while loops first, and then maybe Khaled can understand the real problem at hand, without resorting to feature creep in the parser.

What are the real problems with using "while" that makes "for"/"foreach" superior? Note that "real" should not only include "it takes fewer keystrokes".


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
argv0 #222995 11/07/10 07:02 PM
Joined: Mar 2010
Posts: 146
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 146
Good points argv0.
What I thought at the first place when I posted this topic was just suggesting something that is may useful in mSL. Well, I don't really care about 'foreach' because we haven't any kind of DataType in the mSL and it's really useless, but in that way which is FroggieDaFrog just said is not that so bad to have in mSL. (However I don't care about that again, lol)
FOR loop can be useful because of some reasons:
When we writing a while/goto loop sometimes we just forget to add 'inc' or 'goto there'. (Yes, I agree with that it is our brain that makes this conflicts.) But If we could have the 'for' loop, then we writing all the things which are required (Only) for the loop in the first line and we never will forget them.
By the way, I'm agree with you again, we can do what we need by the 'while' loop and we don't REALLY need that 'for' but it could be better...


Nothing...
Masoud #223000 11/07/10 08:41 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
If remembering to include /inc in a loop is so difficult then scripting isn't a good idea in the first place. Yes, you can forget once in awhile, but it should be rare enough that it shouldn't in any way become a problem or worth the time involved in creating a FOR loop. Besides, it doesn't hurt anything if you do forget. A quick Ctrl-Break and you're ready to fix your mistake.


Invision Support
#Invision on irc.irchighway.net
Masoud #223001 11/07/10 08:46 PM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
The error-prone-ness of /while is certainly something everyone (including me) has run into-- namely forgetting /inc. I think that's probably the best reason to add this sort of syntax.

However, the proposed /for isn't really immune to "forgetting" /inc either. There are plenty of ways to still screw up the for, unless the 3rd argument is required.

Note also that there are some implementation problems in implementing this, specifically that a comma delimiter would not really work. Consider:

Code:
for (var %i = 1, %x = 2, %x < 10 && %y < 20, inc %x, inc %y) { ... }


Since each argument is evaluated as a command, and commands can have ","'s in them, and var in specific does, that becomes problematic. Since ";" is not used as syntax in any commands, it's probably better to use that, but it should have to be space delimited like "|":

Code:
for (var %x = 1, %y = 2 ; %x < 10 && %y < 20 ; inc %x | inc %y)


Of course, with all these syntax peculiarities we're probably introducing *more* error-prone-ness than simply using /while.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Riamus2 #223003 11/07/10 10:07 PM
Joined: Mar 2010
Posts: 146
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 146
What I said was JUST an EXAMPLE. Nevermind, you think you are a genius and you know everything and the rest of people know nothing, heh.


Nothing...
Riamus2 #223164 16/07/10 12:07 PM
Joined: Sep 2009
Posts: 52
Z
ziv Offline
Babel fish
Offline
Babel fish
Z
Joined: Sep 2009
Posts: 52
Pfft, forgetting to /inc is a ridiculously common problem for not just mIRC scripters, but for programmers of any and all languages that allow for such loops in general!

In my years of experience in mIRC scripting I have developed a simple method to semi-counter it.
In every while condition I have, I add "&& $read(<file>,<line>) == 1", and if mIRC freezes on me because of said while loop, I just go(manually) to the file and change that line to "0".

True, this takes more effort then a simple Ctrl+Brake does, but it allows the rest of the code to run, whereas Ctrl+Brake halts the script before the rest of it runs.
Not always a necessity, but it can be useful sometimes.

But I do agree that the while solution is just as good as a foreach, making it not worth the effort.

ziv.

argv0 #223218 18/07/10 04:40 PM
Joined: Apr 2003
Posts: 342
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Originally Posted By: argv0
I think this suggestion in particular is an exercise in form, not function, and misses the point. The classical benefit of a foreach() construct is to allow enumeration via a unified interface for any object/data. Specifically, it allows user-types to be enumerated in the same way builtin-types would be, which is kind of useless in a non-typed language to begin with. Moreover, if you have to pass contextual switches based on the data type, you lose the unified interface and all you're left with is a construct that saves a few keystrokes. Is this really just about vanity?


100% agree. I don't see any satisfiable way of including a "foreach" loop in mIRC's languages which denotes everything as a space delimited string. Not going to work.

Quote:
Let's look at this another way: "while" can do everything mentioned in this thread in roughly the same number of bytes. Why don't we have a discussion about what's wrong with while loops first, and then maybe Khaled can understand the real problem at hand, without resorting to feature creep in the parser.


This is EXACTLY what people would say about using GOTO for looping before the while syntax was added. EXACTLY!


Beware of MeStinkBAD! He knows more than he actually does!
Page 2 of 2 1 2

Link Copied to Clipboard