Mark A. Boyd wrote:
>At 08:10 AM 9/16/00, Colin Holgate wrote:
>>>on killSpaces inStr
>>>   if inStr.word.count < 2 then return inStr.word[1]
>>>   return inStr.word[1] & killSpaces(inStr.word[2..the maxInteger])
>>>end
>>
>>Pretty cute. The only problem is that if you feed a lot of text at 
>>this you get an out of memory error from Director.
>
>I may have spoken too soon in my previous reply to Jakob. While I 
>didn't get the out of memory (only tested up to 27 KB), this time it 
>was just a tad slower than my repeat loop. I suspect the speed will 
>be affected by the content of the string.

Well, I only posted the recursive handler because - as Colin says - 
it's pretty cute.
I just think there is some kind of inspiration in seeing the weird 
and short recursive functions.
But I would never expect it to be faster or more efficient for a 
simple purpose as this.
Recursive processing is more relevant for stuff like 
"multidimensional data of varying depth".
But actually I have made some pretty fast recursive handlers, that 
splits the input string into smaller chunks, and thus benefits from 
Lingo being faster at handling shorter strings.
Here is a recursive splitting handler, that removes lineFeeds from 
long texts fast:
(Could probably even be sped up a bit by using old style syntax)

on CRLF2CR me, a, b
   if b > 1 then
     if b < 4 then
       return a.item[1] & me.CRLF2CR(a.item[2..99999], b - 1)
     end if
     bh1 = b/2
     return a.item[1] & me.CRLF2CR(a.item[2..bh1], bh1-1) &\
     me.CRLF2CR(a.item[bh1+1..99999], b-bh1)
   end if
   if b = 1 then return a
   the itemDelimiter = numToChar(10)
   return me.CRLF2CR(a, a.item.count)
end

This is my take on a fast, simple and robust iterative handler to strip spaces:
(I wrote in more depth about this on direct-l)

on stripSpace  aStr
   the itemDelimiter = " "
   out = EMPTY
   repeat while the number of items of aStr
     put item 1 of aStr after out
     delete item 1 of aStr
   end repeat
   return out
end

I repeatedly evaluate the number of items, because Director seems to 
treat SPACE differently as an itemDelimiter, than other chars. This 
means, that the reported number of items is to small, when you have 
two or more SPACES in a row, in your string. (D7.02 & D8 Mac)

Jakob


[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to