* George Mitchell <[EMAIL PROTECTED]> writes:
> Just for giggles, I decided to write a QT to reverse a string.
Nice one :-)
> %If:"%_Rev_Init"="":"%-
> %___%If:'%_Rev_Src'='':'%_Rev_Src(%Clipboard)'%-
> %___%SetPattRegExp('(?s)(.)(.*)')%-
> %___%_Rev_Out('')%-
> %___%_Rev_Init('T')":""%-
> %-
> %RegExpBlindMatch(%_Rev_Src)%-
> %_Rev_Out("%Subpatt(1)%_Rev_Out")%-
> %_Rev_Src(%Subpatt(2))%-
> %-
> %If:"%_Rev_Src"<>"":"%Qinclude(rev)":"%_Rev_Out"%-
> It works for short strings, but crashes TB! with long ones.
> Does anyone see a problem with my QT or am I just recursing too deep
> and overflowing the stack?
You are recursing too deep, yes.
> If the problem is recursing too deep, is it a bug that I can crash
> TB!, or is this just a case of "don't do that!"?
Two things you could do to harden your QT:
a) Check for the length of the input string (here %CLIPBOARD) and
cut it to a reasonalbe length or print an error message.
b) Reduce the number of recursive calls. You just have to modify two
lines to speed up the QT and increase the maximum size of your
input string:
| [...]
| %_Rev_Out("%Subpatt(3)%Subpatt(2)%Subpatt(1)%_Rev_Out")%-
| %_Rev_Src(%Subpatt(4))%-
| [...]
(BTW: you should add this one to Marcks QT Library)
Carsten
--
________________________________________________________
http://www.silverstones.com/thebat/TBUDLInfo.html