mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
i started fiddling with the idea of a scripted multiline for:
Code:
alias hello { 
  for (%x = 0;%x <= 5;+) $scriptline { 
    echo -a yay
    echo -a MultiLine! :D
  }
  echo -a Such a crappy for loop implementation :P
}
alias tok return $gettok($1,$2,32) 
alias for { 
  !noop $regex($1-,/\((.+?);(.+?);(.+)\)\s(\d+)/)
  set -l $tok($regml(1),1) $tok($regml(1),3)
  var %s = $regml(4) + 1 , %crement = $replace($regml(3),+,inc,-,dec) $tok($regml(1),1) , %condition = $regsubex($regml(2),/(\w+)$/,$calc($(\1,2) -2)))
  window -h @cool
  filter -fwgnr $+(%s,-999999) $qt($script) @cool /^\s*?}\s*?$/
  var %e = $tok($line(@cool,1),1) - 1 
  window -c @cool
  tokenize 32 %condition
  while ($($1,2) $2 $($3,2)) {  
    filter -fkgr $+(%s,-,%e) $qt($script) forcommands 
    %crement
  }
}
alias forcommands $1-


Its crappy coded, no error checking. Just to prove it is sorta possible smile


$maybe
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: Mpdreamz
Tis a lot more annoying to type out then

.
.
.

It just looks ALOT better the pure aesthetic reasons are enough for me to want it BAD.


That's a matter of opinion. I like the look of the while more than the for in your examples. It's similar to the idea that you can type a lot of commands on one line, but it is nicer looking and easier to read (imo) to have them on separate lines.


Invision Support
#Invision on irc.irchighway.net
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Which is fair enough, to each their own smile
I did say "the pure aesthetic reasons are enough for me to want it BAD."
It doesn't hurt implementing.

my example was completely non spaced which would be sucky
Code:
for (%x = 0, %y = 10; %x <= %y; inc %x) { 
}


I would far from class this as putting alot commands on one line (something which is backwards to do) you merely instruct the parser to start looping on one line.


$maybe
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: Mpdreamz
I would far from class this as putting alot commands on one line (something which is backwards to do) you merely instruct the parser to start looping on one line.


What I meant by that is that you are putting all the variables and increment/decrement on a single line. As a while, it would look similar to:

Code:
var %c = 1, %i = 10 | while (%c <= i) { inc %i
  do stuff
}


Granted, that's really ugly, but it is just an example of what I meant by putting a lot of stuff on one line rather than separating it. And it is actually not very much longer than the for line (basically just the while included makes it longer -- or the length of while mixed with including var).

That example should do what the for would do EXCEPT that it would increment before doing the commands, rather than after. Of course, you can "fix" that from being a problem by using variables that are set to 0 and 9 (1 less). Yes, that's more troublesome, but it's just to illustrate my point.

As I have said, I don't care if FOR is added. I don't personally see a need for it, but it won't hurt me any if it is added for those who prefer it to using WHILE.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 12
S
SartenX Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Jul 2006
Posts: 12
Riamus: I'm of the opinion that a for loop as a command would be nice, but very unnecessary. If you're going to be writing many lines anyway, a few more won't hurt. using a while is closer to assembly anyway. I realize that mIRC doesn't use ASM, but the logic's the same. All looping structures are identical at the logical level.

I'm just looking for an easy way to do easy things.

Mpdreamz: A local variable would work well. I was thinking like perl, where it just knows how much data is available. Or maybe I just wasn't thinking...

Merry Christmas, y'all!

Joined: Mar 2006
Posts: 8
A
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
A
Joined: Mar 2006
Posts: 8
I prefer this:

Code:
foreach %nick ($nick(#, rovha)) {
  echo -a %nick
}

foreach %address ($ial(#).all) {
  echo -a %address
}

foreach %line (@window) {
  echo -a %line
}

foreach %line ($readAll(readme.txt)) {
  echo -a %line
}

foreach %ini ($ini(file.ini).headers) { }

foreach %ini_items ($ini(file.ini, header).items) { }

foreach %key, %value ($hashtable(name)) {
  echo -a %key = %value
  ; automatically extracting the $hget(name, key) and its value, python dict style
}


Originally posted at http://www.mircscripts.org/forums.php?cid=4&id=157414#157414

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
That doesn't match any existing mIRC syntax. I think it's a bad idea to bring in things like that. There should be a level of consistency.

Code:
foreach (%nick,$nick($chan,rovha)) {

}


The above would at least be similar to what exists already. To be honest though, I don't see the point in a foreach loop for mIRC. foreach is really something I'd only consider useful in an OOP language.

PS.
In the above example, how would mIRC know where to put to put the incrementation variable? ($nick($chan,N,rovha))
Unless you're suggesting that $nick($chan,rovha) return an array/collection, which would need to be implemented first.

Joined: Mar 2006
Posts: 8
A
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
A
Joined: Mar 2006
Posts: 8
Yes I'm suggesting that those identifiers would return some kind of array collection that is only accessible with the foreach loop. See the ms.org posting for updates. Something like this:

Code:
foreach ($read(file.txt, not_sure_about_second_parm)) {
  $v1 would contain the line being read
}

foreach ($nick(#, rovha)) {
  $v1 would be the nick
}

Last edited by astigmatik; 16/02/07 04:07 AM.
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
That makes a little more sense.

I think that would require almost every identifier to be rewritten for the foreach loop though - if so, I think there's slim chance of that happening.

Page 2 of 2 1 2

Link Copied to Clipboard