Re: stack overflow error processing text file [relsit: can't
Re: stack overflow error processing text file [relsit: can't
- Subject: Re: stack overflow error processing text file [relsit: can't
- From: email@hidden
- Date: Tue, 17 Jul 2001 21:55:44 -0400
On Tue, 17 Jul 2001 19:24:23 -0400,
monk <email@hidden> asked,
>
i also get a'stack overflow' on the similar script (optimized) below on the
>
line with: random number from 1 to pcount
[...]
>
on mix(mytext, mymix)
>
set text item delimiters to space -- you want to get the paragraphs
>
set mymix to text items of mymix
>
set mytext to text items of mytext -- these two lines coerce text into
>
list
>
set pcount to count of text items of mytext
>
set k to random number from 1 to pcount -- random element chosen.
>
Michelle Steiner's better line of code
>
set mymix to mymix & text item k of mytext -- added to _mix
>
if pcount = 1 then
>
--set mymix to rest of mymix
>
set mymix to mymix as string
>
set text item delimiters to "" --default
>
return mymix
>
end if
>
set item k of mytext to {}
>
set mytext to every string of mytext -- Arthur Knapp's clever idea
>
mix(mytext, mymix) -- using recurrence. You want to do it until _source
>
empty
>
end mix
[...]
This isn't a good way to use a recursive call, and using it is what is blowing
out your stack. The actual error occurs when you call the 'random number'
scripting addition command, but only because all the recursive calls to mix()
have eaten up all the stack.
Just put the body of the handler in a "repeat" loop, and you won't use any
stack.
If you are working through a list, use iteration. If you are working through a
tree, use recursion.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden