mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#222851 06/07/10 07:40 PM
Joined: Mar 2010
Posts: 146
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 146
I think mIRC may have a FOR loop...
What do you think about that?


Nothing...
Masoud #222852 06/07/10 07:48 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I would love to see this added, but maybe with a "," delimiter instead of ";" to match the rest of the language:

Code:
for (var %x = 1,%x <= 10,inc %x) {
  echo -a %x
}


Output:

1
2
3
4
5
6
7
8
9
10

I also think the first parameter for for () should accept all variations of the var/set commands:

Code:
for (var %x = 1,%x <= 10,inc %x) {
  echo -a %x
  ; %x is local to the for loop so this will display.
}
echo -a %x
; this will throw an error unless %x is a global variable, as the local variable %x above was unset upon the termination of the loop.


Code:
for (set -u %x 1,%x <= 10,inc %x) {
  echo -a %x
}
echo -a %x
; Both %x 's will display but %x will unset at the end of the current code block.


Code:
for (set %x 1,%x <= 10,inc %x) {
  ; %x is global here and will return a value until it is unset. 
}

hixxy #222858 06/07/10 08:27 PM
Joined: Mar 2010
Posts: 146
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 146
It's good hear that. I hope that Khaled will doing something about this good and useful feature wink


Nothing...
Masoud #222860 06/07/10 10:12 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Just as a note... It's been suggested many times in the past, so I wouldn't get your hopes up on it being added really soon. Maybe it will, but it appears to be either low down on Khaled's to-do list or he has decided not to do it at all.

FOR can be useful, but it really isn't that much different to use a WHILE loop. Yes, it's more lines, but the end result in most situations will be the same and I have a feeling that it wouldn't even be more efficient because it will still be executing the same commands.

I don't much care either way. It's so common in programming and scripting languages that I agree it should also be here, but it's so easy to do the same thing with WHILE that I don't think there's any rush to get it added either.


Invision Support
#Invision on irc.irchighway.net
Masoud #222861 06/07/10 10:42 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I would also like to see switch/case blocks:

Code:
var %x = 10
switch (%x) {
  case (1) { ; %x = 1 }
  case (> 5) { ; %x is more than 5 }
  case (<= 5) { ; %x is less than 6 }
}

Riamus2 #222862 06/07/10 10:53 PM
Joined: Mar 2010
Posts: 146
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 146
Yes, I know what i said can be suggested many times before. But i just said my suggestion and opinion.

What you just said is right but i have a question from you: "Why don't you use 'goto' loop instead of 'while' loop?"

The answer is pretty easy: "Because 'while' is doing much better and it takes less codes and less mistakes."

So YES, they are the same. BUT when there is a better feature than 'while' (Which is 'for') Why shouldn't we be able to use it? By the way, I don't really think that is SO HARD to exert for Khaled. He can set it up so easily.

What do you think now Riamus2?


Nothing...
hixxy #222863 06/07/10 10:55 PM
Joined: Mar 2010
Posts: 146
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 146
Yeah hixxy, that's a really good suggestion/idea. And i like to use a 'try/catch' blocks too!


Nothing...
hixxy #222870 07/07/10 07:18 AM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: hixxy

I also think the first parameter for for () should accept all variations of the var/set commands:


hey hixxy :P i think it would be more sensible to have the first (and third) parameter function equivalent to how the command parameter in $findfile() does; it would be more aligned with for() implementations in other languages, wouldn't be entirely out of place, and would make the command suitable for a wider variety of applications


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
hixxy #222872 07/07/10 07:54 AM
Joined: Dec 2002
Posts: 122
S
Vogon poet
Offline
Vogon poet
S
Joined: Dec 2002
Posts: 122
Originally Posted By: hixxy
I would also like to see switch/case blocks:

Code:
var %x = 10
switch (%x) {
  case (1) { ; %x = 1 }
  case (> 5) { ; %x is more than 5 }
  case (<= 5) { ; %x is less than 6 }
}


Agreed!

Masoud #222891 07/07/10 10:26 PM
Joined: Mar 2010
Posts: 146
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 146
I wanted to get at least an answer from Khaled and read his explanation about this. (Or maybe he already respond in the same other topics. I don't know.)
By the way, I didn't got any answers.
Whatever, Have fun guys.


Nothing...
Masoud #222895 07/07/10 11:00 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
So you know, Khaled rarely replies to feature suggestion topics. He'll reply about bugs either asking for more information or to say that it's fixed for the next release or sometimes to explain why it's not a bug or how to get around it. He also responds to some of the other forums regarding connection issues or requesting help with mIRC. But he just doesn't usually respond in this forum or the script help forum. So don't take that to mean that he isn't reading or doesn't agree with your suggestions.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #222896 07/07/10 11:22 PM
Joined: Mar 2010
Posts: 146
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 146
Yeah, I know that BUT "Reading topics" is not enough. mIRC Users in here need answers. ( I don't mean that he should reply to all of the topics, but this kind of topics are different.)
If people know that they just wasting their time in here without any answers, then they won't post anything in here and it's a dead-end for this primary mIRC's forum...


Nothing...
Masoud #222897 08/07/10 12:15 AM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Your opinion is noted, but it probably won't change the way Khaled handles feature suggestions.

If you consdier suggesting something a "waste of time", don't suggest it; simple as that. Suggesting a feature is not a guarantee that it will be implemented-- you knew that before you posted (you should have, anyway, since that's how "suggestions" tend to work). Therefore, Khaled's response or lack thereof won't change anything. Furthermore, it's probable that Khaled does not respond to these threads because:

1) There are no plans to implement the suggestion (ever) and he finds no reason to have to discuss his decision.
2) He's responded to a thread on the same suggestion before and does not need to respond to the same issue again.
3) He does not want to commit to implementing (or not implementing) a feature that may turn out to be too difficult or time consuming to implement properly.

With these reasons in mind, Khaled often does not respond to feature suggestions. I'm sure you can accept that.

Note that the feature suggestions forum is in no way a "waste of time". Just about every feature Khaled has ever implemented has originated from this forum, so your claim that not knowing whether a suggestion will be implemented makes posting a waste of time, is categorically false. People don't post suggestions so they can see Khaled respond to them. They post suggestions so that they can make it into mIRC. The only way you waste your time is if the feature you suggest will never be implemented-- which, by the way, pretty much sums up all the suggestions in this thread, which have been suggested many times before but never been implemented.

As far as the suggestions actually go: for loops are just glorified while loops, which already exist in mIRC. There's no real need for the syntactic sugar, since you don't even really save on number-of-bytes. switch cases can be useful, but again, they're mostly just syntactic sugar and are likely too complicated for Khaled to focus on with so many other features to deal with. Try/catch is pretty much useless, since mIRC has no concept of exceptions besides the half-baked :error label. For try-catch to work, Khaled would need to create an entire exception handling mechanism, which is relatively difficult and extremely unlikely.

It should also be pointed out that, in general, Khaled does not like to touch the parser much. The last time he did (6.33), he broke /if completely and had to put out another version (6.34) within ~48 hours. Therefore suggestions regarding the parser and the language syntax are generally hard to get through in the first place, and you shouldn't really expect any form of commitment on these.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
argv0 #222912 08/07/10 10:32 PM
Joined: Mar 2010
Posts: 146
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 146
You got wrong what I meant about the "Wasting time"; I didn't say it's REALLY wasting time... There is a "IF" in the start. (Or maybe my English is weak and I couldn't said that what i meant exactly.)
I'm like-minded by the rest of your comment except of what you said about "/if", What me and some others suggested in here is not really that SO hard thing like "/if"...
By the way, thanks for your time/comment/information.


Nothing...
Masoud #222932 09/07/10 07:48 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
I'd also Like to see a foreach loop:


foreach (string,delimiter) { }
Code:
foreach (this is a string,32) {
  echo -a $fedata
}
would echo:
this
is
a
string


foreach -h (hashtable,<condition>)[.data] { }
Code:
 foreach -h (table,*match item*) {
  echo -a $feitem $fedata
}
echo each matching item, and it's data.
the .data property would have the loop match data


foreach -i (inifile,[topic],<condition>) { }
Code:
foreach -i (inifile,sometopic,*).data {
  echo -a $fetopic $feitem $fedata
}
matches items in an ini file.
the .data property will have the loop match data







I am SReject
My Stuff
FroggieDaFrog #222934 09/07/10 10:30 PM
Joined: Sep 2009
Posts: 52
Z
ziv Offline
Babel fish
Offline
Babel fish
Z
Joined: Sep 2009
Posts: 52
All good ideas.
It's true, you could accomplish for with while and switch with ifs, but I'de still like to see 'em implemented, and the foreach idea is AWESOME!
(Of course, you can do "var %x = <condition> | if (%x == case1) { } | elseif (%x == case2) { } ..." <- Switch&cases.)
("tokenize 32 <string> | var %i = 1 | var %word = $ [ $+ [ %i ] ] | while (%word) { echo -a %word | inc %i | var %word = $ [ $+ [ %i ] ] }" <- Foreach, or somwthing like this...this was just something done on the spot... xD)

ziv.

FroggieDaFrog #222971 11/07/10 05:08 AM
Joined: Feb 2004
Posts: 206
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
Code:
tokenize delimiter, string
<command> $*

e.g.
Code:
tokenize 32 this is a string
echo -a $*

would echo:
this
is
a
string

I don't have mIRC open, so my syntax on tokenize may be slightly wrong - check the help file.

Cheers,

DK


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
Darwin_Koala #222973 11/07/10 05:28 AM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Originally Posted By: Darwin_Koala
Code:
tokenize delimiter, string
<command> $*

e.g.
Code:
tokenize 32 this is a string
echo -a $*


First off $* is undocumented so it could be removed at any time without any notification.
Second, try doing multiple commands with $*. To do so, you have to write an alias.
Third, try doing something like:
Code:
tokenize 32 this is an example | if ($* == is) { echo -a $v1 }


I am SReject
My Stuff
FroggieDaFrog #222975 11/07/10 09:01 AM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: FroggieDaFrog
I'd also Like to see a foreach loop:


foreach (string,delimiter) { }
Code:
foreach (this is a string,32) {
  echo -a $fedata
}
would echo:
this
is
a
string


foreach -h (hashtable,<condition>)[.data] { }
Code:
 foreach -h (table,*match item*) {
  echo -a $feitem $fedata
}
echo each matching item, and it's data.
the .data property would have the loop match data


foreach -i (inifile,[topic],<condition>) { }
Code:
foreach -i (inifile,sometopic,*).data {
  echo -a $fetopic $feitem $fedata
}
matches items in an ini file.
the .data property will have the loop match data



i like the general idea, but implementation in the nature that you described seems complicated and messy. the notion of a control structure such as the proposed foreach() having these accompanying switches and identifiers is quite bizarre, albeit a novel one :P the task of iterating is not made any simpler since, it seems, a user would be required to understand and be familiar with the behaviour of $gettok, $hfind and $ini to be able to effectively use those that you mentioned. the end result of one of these loops would resemble currently scriptable methods in complexity and size, so it doesn't appear to provide enough added benefit to the scripting language.

i had a similar thought a couple of weeks ago while we were discussing a hypothetical foreach() on EFnet's #mIRC. suggestions were being thrown around and my thoughts gradually converged upon an idea that, at the time, i believed to be epiphanic. what if we could abstract the idea away from association with any particular command or identifier and create a general purpose foreach () that would iterate through a collection of items exactly as $submenu() does (send 1 to the alias/identifier and keep increasing until it returns $null). an example might be:

Code:
foreach ($gettok(%var, $1, 32)) {
  ; $v1 is filled with the return value
}


but quick as the idea came to me, so too was it dismissed as i realized the obvious folly: that it is, for all intents and purposes, equivalent to:

Code:
var %i = 1
while ($gettok(%var, %i, 32) != $null) {
  ; $v1 is filled with the return value
  inc %i
}


i had mentally tweaked and adapted the idea to the point where it resembled, almost entirely, something that is readily available to me already ;D great story right


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
jaytea #222977 11/07/10 10:28 AM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Originally Posted By: jaytea
Originally Posted By: hixxy

I also think the first parameter for for () should accept all variations of the var/set commands:


hey hixxy :P i think it would be more sensible to have the first (and third) parameter function equivalent to how the command parameter in $findfile() does; it would be more aligned with for() implementations in other languages, wouldn't be entirely out of place, and would make the command suitable for a wider variety of applications


Could do,

But do you think there are many commands other than the variable related ones that have a place in for () ?

Things like this, for example, wouldn't really be very good methods to achieve something:

Code:
var %i = 10 
for (hadd -m test test 1,$hget(test,test) <= %i,hinc test test) {
  echo -a $hget(test,test)
}

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 1 of 2 1 2

Link Copied to Clipboard