mIRC Home    About    Download    Register    News    Help

Print Thread
#116097 02/04/05 01:02 PM
Joined: Mar 2005
Posts: 11
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Mar 2005
Posts: 11
Recursion could be a handy feature, and solve a lot of complex scripting problems the easy way

Yes, I am aware about the text in help file:
An alias cannot call itself recursively mainly because this seems to cause more problems for users than it solves
but I do not see the logic: Why does recursive code cause more problems than it solves?

I have tried doing a search on this suggestion, and found a 2 year old post, but it seems like it was never answered: here

#116098 02/04/05 02:22 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Recursion is already possible indirectly. An alias cannot call itself, but it can call another alias, which in turn can call the first (see this post for details).

The reason direct recursion is disabled is simply that the majority of scripters aren't familiar with recursion and its results. Calling an alias from within itself, by mistake, can give results that novice scripters may not expect or be able to explain (results that are usually much less intuitive than a freezing loop, for example). To those scripters, recursion does "seem to cause more problems than it solves". More advanced scripters who really need recursion can simply do it indirectly, with very little effort.

That said, I wouldn't mind a recursive capability in aliases, as long as it's specified explicitly, like the alias -r { code } that has been suggested before. This way novice scripters are 'protected' while those who need recursion are saved the (very small) extra code/overhead of indirect recursion.

Last edited by qwerty; 02/04/05 02:28 PM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#116099 02/04/05 03:14 PM
Joined: Mar 2005
Posts: 11
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Mar 2005
Posts: 11
Quote:
The reason direct recursion is disabled is simply that the majority of scripters aren't familiar with recursion and its results.


This argumentation does not make sense.
People starting with C or java are not familiar with recursion either. But they have to learn it if they want the best algorithms.

#116100 02/04/05 11:11 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
The arguement made perfect sence, your use of mentioning two languages that dont, doesnt make it less so, mIRC is a chat client first a programming language second, can the same be said for the ones you mentioned?
I would say and this is an opion that the majority of scripters in mirc are novices, dabling lightly to complete simple tasks they have to do with there chatting in one way or another.

You were explained how to create recursion its not like its hard you know.

example.

Code:
alias wordlengths {
  echo -a Word " $+ $$1 $+ " is $len($1) characters in size
  wordlengths_ $2-
}
alias wordlengths_ { wordlengths $$1- }


WOW one whole extra line!

#116101 03/04/05 12:54 AM
Joined: Dec 2002
Posts: 208
H
Fjord artisan
Offline
Fjord artisan
H
Joined: Dec 2002
Posts: 208
The thing is, if you were to write, say, a /msg alias, then you cannot use /msg, or .msg, in order to send the text, at least so long as recursion is allowed. For example, you might have something to change the way messages look when sent, like:

alias msg {
echo -ta ( $+ $me $+ -> $+ $1 $+ ) $2-
.msg $1 $2-
}

That would be an infinite loop if recursion is allowed, and might go unnoticed in a more complicated alias. Anyone with something like that would have to go through to replace that command with /raw privmsg, !msg, etc instead, which is just extra work. On the other hand, if you happen to need recursion in an alias for a chat program, which i imagine would have to be relatively rare, the two-alias method is fine, and leaving things the way they are won't break anything.

P.S. If you need efficiency, why are you writing it in mirc script to begin with?


If I knew now what I will know then... maybe things will have been different...
#116102 03/04/05 02:37 AM
Joined: Mar 2005
Posts: 11
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Mar 2005
Posts: 11
Quote:
mIRC is a chat client first a programming language second, can the same be said for the ones you mentioned?


there is no first and second. mIRC should have both characteristics at once.

Quote:
If you need efficiency, why are you writing it in mirc script to begin with?


That mIRC "only" is a chat client, is not a good argument to use against improving the scripting feature.

#116103 03/04/05 02:53 AM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Couple of notes:

1) That previous thread is actually only 9 months old (you probably looked at the original poster's 'reged' date by mistake), so there hasn't been a new version of mIRC since that thread took place (well OK, 6.16 was released two days later - but it was hardly gonna be added in that time). Which means recursion have been implemented already and we just don't know it yet.

2) If by 'never answered' you mean Khaled didn't respond personally, then about 99.999% of the feature suggestions aren't answered. Typically, the 'answer' comes in the form of whether the feature is implemented in the next version of mIRC (in which case, see point 1 again).

As for the 'causes more problems than it solves', well that's simply down to the fact that mIRC scripting is generally designed to be as newbie-friendly as possible, whereas a 'proper' programming langauge is more concerned with providing power and efficiency with the cleanest code possible. Even if that weren't the case, by already allowing a command to be called within an alias of the same name and having it behave as the built-in command (eg. alias msg msg $$1- $+ !!!!!) it'd be impossible (read: stupid) to change that behaviour now to act as recursion. That is, unless the alias switch idea or something else along those lines is used, in which case all those problems go away and nobody can complain one bit.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#116104 03/04/05 03:18 AM
Joined: Mar 2005
Posts: 11
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Mar 2005
Posts: 11
I agree that the recursive behavior of commands should be implemented as a switch, to avoid confused users.

#116105 03/04/05 03:28 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
Quote:
mIRC is a chat client first a programming language second, can the same be said for the ones you mentioned?


there is no first and second.


Yes there is 1st comes before 2nd, you see thats the order of things first comes well First, second comes second you see? <snicker snicker>

Quote:
mIRC should have both characteristics at once.


It does But again First its a chat client and second its a programming language, in fact second its a programming language based loosely around usage for chatting/irc. (i dont really see many accounting packages for instance being created with it)

And if you think its a programming langauge then why doesnt VBnet including a chat client!!?!?!?!?!?!?!?! (a completely pointless arguement i just made of course but funny regardless)

#116106 03/04/05 03:39 AM
Joined: Mar 2005
Posts: 11
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Mar 2005
Posts: 11
Quote:
its a programming language based loosely around usage for chatting/irc. (i dont really see many accounting packages for instance being created with it)


This is irrelevant. Improving the efficiency is useful no matter what. The fact that mIRC scripting not is a "real" programming language, should not prevent it from evolving.

#116107 03/04/05 05:35 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
It doesnt need to "evolve" recursion is completely possable, it was deliberatly blocked by the designer, as his feelings (and likely research) was that the majority of users well find recursion more problems than its worth, so as to the "efficiency" well its not efficient if it causes a majority of users problems, no matter how wizbang the feature is for a minority.
The minority who might need it, (i have been one) well find working around the block placed on for the majority, hardly a difficulty

example code.
Code:
alias wordlengths {
  echo -a Word " $+ $$1 $+ " is $len($1) characters in size
  recurse wordlengths $2-
}
alias recurse { $$1- }


Now its one line extra for as many different aliases recurasing as you like and the word recurse infront of the recursing alias which makes it clear what your doing even!

* Side note : v6.16 has a fault in it that if u do start recursing the call depth check appears broken, you used to only be able to go down 1000 or so calls, right now it just crashes mirc at some point less than this 450 or so, but this appears to be a bug, that i assume well be fixed by next version. On this personally if your recursing that much then u likely could have done something different or should create your own data stacks, and stay with in the same call.

#116108 03/04/05 10:11 AM
Joined: Dec 2002
Posts: 208
H
Fjord artisan
Offline
Fjord artisan
H
Joined: Dec 2002
Posts: 208
All I meant was that if it is important to be efficient, you should consider writing a dll, or seperate exe to do the job.. just a straight translation of code between mirc and a compiled language, like c, would probably yield vast speed improvement, even before optimizing it. mIRC script has basically evolved as a way to do stuff on irc to enhance chatting. As such, there is no need to turn it into a stream-lined, number-crunching, bit-twiddling, pixel-pushing dynamo. Not that a script could ever be as efficient as a well-written program in a compiled language.

Last edited by Hrung; 03/04/05 10:23 AM.
#116109 03/04/05 10:55 AM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
By using indirect recursion you're halving the effective recursion depth to a rather meagre 500 or so (or much less in the current version). Direct recursion has it's benefits, and as has been said about half a dozen times already a switch could be used to require a conscious decision to enable recursion for a given alias thereby removing the 'newb factor'. I don't see why you'd be against something that would be beneficial to a lot of scripters, including yourself, with no drawbacks.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#116110 03/04/05 03:14 PM
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Quote:
By using indirect recursion you're halving the effective recursion depth to a rather meagre 500 or so


With the handy tools ctrl-c and ctrl-v you can even help that. 2 aliases with the same function calling eachother, thats copy, paste and change 2 names from myrecursealias to myrecursealias2.

#116111 03/04/05 04:22 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
True, but then you've got to have two alias names for every single recursible alias, which just seems wrong on so many levels.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#116112 03/04/05 10:50 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Im not against recursion at all, Im just against the status quo being altered, I dont consider an -r switch altering the status quo tho, as thats an extention, and would be fine with that, in fact bring it on!, I was going to mention duplicating the alias and calling the other one (which i do find pretty a repulsive idea personally) as the method to up the count to 1000, but really I feel that if you know how many recursions your going to need or suspect that depth is needed then you likely know you should be looking to do it another way, something flat which keeps its own stack table.

My only gripe on "recursion/alias's calling themselfs" is currently an alias cant call itsself FINE why cant it call another alias called the same thing!
ie:
I write
alias msg { msg $1 Attention message from $me follows $$2- }
^ Thats fine it works.

But what if there is also an alias present (maybe in some addin script) such as
alias msg { var %text | scon -r var $+(%,text) = $+(%,text) $!+($upper($left( $* ,1)),$mid( $* ,2)) | msg %text }
^ this well never get processed

* I really find being able to replace a comand with an alias helpfull, but i dont find its helpfull to not be able to allow other scripts access to the command after mine.
Assuming this was done it would not need to cause recursions back into the first script, becuase it could be riggered that it only scans from the current script downward for a identical name alias, since any before it have already been run once., this would be supperseeded by an -r switch which says run myself if i call myself ect.
** I have actually built a workaround for this problem so i dont actually need anything changed, but i just felt it would be nice as well.

#116113 26/04/05 01:16 PM
Joined: Sep 2003
Posts: 5
B
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
B
Joined: Sep 2003
Posts: 5
Code:
alias command {
  echo -a $1 $+ $1
  .timer -m 1 0 command $1 $+ $1
}


enjoy...

#116114 26/04/05 01:26 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
This isn't even recursion...


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#116115 22/05/05 06:35 AM
Joined: Dec 2002
Posts: 580
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
this is though... I've posted it before, but....

Code:
alias blah { .signal -n RECURSION }
on *:signal:RECURSION:{
  var %Level
  if ($1 == $null) { set %Level 1 }
  else { set %Level $1 }
  echo -a Recursion Level: %Level
  if (%Level &lt; 5) { .signal -n RECURSION $calc(%Level + 1) }
  echo -a Recursion Level: %Level
}


NaquadaBomb
www.mirc-dll.com

Link Copied to Clipboard