mIRC Homepage

FYI: Recursion with signals :)

Posted By: NaquadaServ

FYI: Recursion with signals :) - 09/10/04 06:49 AM

Sorry if I'm saying something everyone else knows but...

I finally figured out a way to recurse with mirc... You can recurse with signals...

Basic Resursion Idea (This really works, I'm so happy!!!)
Code:
alias do_recurse { .signal Recurse 1 }
on *:signal:Recurse:{
  echo Resurse Start: Level $1
  if ($1 < 3) { .signal -n $signal $calc($1 + 1) }
  echo Resurse End: Level $1
}


The output for do_recurse is:
* Resurse Start: Level 1
* Resurse Start: Level 2
* Resurse Start: Level 3
* Resurse End: Level 3
* Resurse End: Level 2
* Resurse End: Level 1
Posted By: qwerty

Re: FYI: Recursion with signals :) - 09/10/04 09:08 AM

There are much simpler (and safer) ways to have recursion. Just make two aliases call each other:
Code:
alias one if $1 < 5 { echo 3 -s Start: $1- | two $calc($1 + 1) | echo 3 -s End: $1- }
alias two if $1 < 5 { echo 4 -s Start: $1- | one $calc($1 + 1) | echo 4 -s End: $1- }
Then type:

//one 1

You can call /two either at the beginning or at the end of the code for the /one alias, depending on what you want to do.

If you want to have a general-purpose do_recurse you can also do this:
Code:
alias do_recurse $1-


The methods using aliases are safer than signals, except in the current version of mIRC. The safeguards that were implemented quite a few versions ago seem to be broken in v6.16, but I'm sure they will be fixed, since they used to work fine. Signals, on the other hand, were never recursion-safe: you can crash any version of mirc with something like:
Code:
on *:signal:crash: .signal -n crash
by typing
//signal crash
Posted By: NaquadaServ

Re: FYI: Recursion with signals :) - 10/10/04 05:58 PM

Not a bug!!! Just cleaner than your two alias example and if you "can" do it with two aliases, you "can" do it, removing this ability isn't making mirc any safer, in fact it would piss me off to the point where I would never change versions...

Signals are prefect as they are... smile
Posted By: qwerty

Re: FYI: Recursion with signals :) - 10/10/04 06:18 PM

I have to say that I didn't understand your last post. I suspect you didn't fully undestand mine either wink

Currently, both ways, aliases and signals, allow recursion and I have no objection to that (in fact I like it this way). I was just saying that the aliases method does not allow infinite recursion, thus protecting mirc from crashes due to stack overflows.The maximum recursion depth in aliases is 500 or 1000 (depends on whether the aliases are called as identifiers or commands). This protective mechanism is broken in v6.16 but as soon as it's fixed, the aliases method will be safer than signals while providing the same functionality (unless you need a depth > 1000, which is highly unlikely).
© 2020 mIRC Discussion Forums