mIRC Home    About    Download    Register    News    Help

Print Thread
Recursion #88886 02/07/04 06:20 PM
Joined: Jul 2003
Posts: 33
B
Bilge Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2003
Posts: 33
I have just built a fairly complex recursion routine but it seems that I get an error when the alias calls itself - mIRC sends the name of the alias to the server instead of recalling it. Is this possibly due to an error in my script, which I can't seem to find, or is this because mIRC does not support recursion?

Re: Recursion #88887 02/07/04 06:50 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
From the help file:
Quote:
An alias cannot call itself recursively mainly because this seems to cause more problems for users than it solves.


You can get around this by using scon/scid with the command, or you can use simple indirect recursion (ie. /alias1 calls /alias2 which calls /alias1 again). Be aware though that with both of these methods you're calling two commands for each level of recursion which means you can only have a maximum recursion depth of 500.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Recursion #88888 02/07/04 06:58 PM
Joined: Jul 2003
Posts: 33
B
Bilge Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2003
Posts: 33
The /scid workaround would be nice if it worked, but it does not. This does allow the command to call itself but it does not allow the first instance of the alias to continue when all child instances have completed.

If it might help then I will include the code:
Code:
alias lema.recurse.thememsg.buildbracematrix {
  ;Usage: %ht %node %msg
  var %ht = $1, %level = $2, %j = 1, %node, %re = /(\([^(]*?((?:\(.*\))?)[^(]*?\))/g
  tokenize 32 $3-

  ;In the following regex all odd numbers contain level root_level braces, all even numbers contain root_level+1 braces or null if no nested braces
  ;Because root_level+1 may also have a +2 level and +3 and so on, recursion must be used until all even numbers return $null
  void $regex($1-,%re)
  while (%j <= $regml(0)) {
    %node = $+($iif(%level,$+(%level,.)),$round($calc(%j / 2),0))
    if ($isodd(%j)) hadd %ht %node $regml(%j)
    elseif ($regml(%j)) scid $cid lema.recurse.thememsg.buildbracematrix %ht %node $regml(%j)
    inc %j
  }
}
The alias is first called from another alias to initialise it and is initialised as follows:
lema.recurse.thememsg.buildbracematrix %ht 0 $1-
where %ht is a hash table name and $1- is some data containing nested parenthesis.

Re: Recursion #88889 02/07/04 08:07 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Without carefully examining your code, I noticed a potential problem with $regml(). $regml() is not local to the routine that calls it, it's like $ifmatch and global variables. Meaning that a child /lema.recurse.thememsg.buildbracematrix would corrupt the while (%j <= $regml(0)) of the parent. You need to use unique names with $regex/$regml to get around this problem ( $regex(name,text,/pattern/) ). From what I see, %node would be a good candidate for a named $regex.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: Recursion #88890 02/07/04 08:25 PM
Joined: Jul 2003
Posts: 33
B
Bilge Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2003
Posts: 33
Thank you both for your great help! I think you meant %level rather than %node... it's a bit quirky. %node gets passed back to the function as %level, and then when it is modified becomes %node. I originally called it %level and %newlevel. I guess that way it made more sense.

Anyway it works properly now thanks to the combination of both of your tips. Cheers guys.

Re: Recursion #88891 05/07/04 01:50 AM
Joined: Jul 2003
Posts: 33
B
Bilge Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2003
Posts: 33
What about if I need to call a custom identifier which provides a return value recursively? $scid($cid) properties cannot contain brackets and therefore no parameters can be passed to the identifier, and they need to be.

Re: Recursion #88892 05/07/04 04:24 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
I think in that case your only option is to use the indirect recursion method. alias1 returns alias2 returns alias1


Spelling mistakes, grammatical errors, and stupid comments are intentional.