• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: stack overflow error processing text file [relsit: can't
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stack overflow error processing text file [relsit: can't


  • Subject: Re: stack overflow error processing text file [relsit: can't
  • From: Deivy Petrescu <email@hidden>
  • Date: Wed, 18 Jul 2001 13:14:34 -0400

At 9:55 PM -0400 7/17/01, email@hidden wrote:
On Tue, 17 Jul 2001 19:24:23 -0400,
monk <email@hidden> asked,

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

You are absolutely right. The recursive call here is unnecessary, ineffective and longer.
This works!

<script>
try
set _source to open for access (choose file with prompt "choose source to mix:")
set mtext to (read _source) as text
close access _source
set _mix to open for access file (((path to desktop) as string) & "mixed") with write permission
mix(mtext, _mix)
on error
close access _source
close access _mix
end try
close access _mix

on mix(mytext, _mixed)
set pcount to count of text items of mytext
repeat until pcount < 1
set text item delimiters to return
set mytext to text items of mytext
set k to random number from 1 to pcount
write (contents of item k of mytext & return) starting at eof to _mixed
set item k of mytext to {}
set mytext to every string of mytext
set pcount to pcount - 1
end repeat
set text item delimiters to ""
set mytext to ""
return 0
end mix
</script>

Deivy Petrescu
http://www.dicas.com


  • Follow-Ups:
    • Re: stack overflow error processing text file [relsit: can't
      • From: monk <email@hidden>
References: 
 >Re: stack overflow error processing text file [relsit: can't (From: email@hidden)

  • Prev by Date: Re: Simply- A fix to link
  • Next by Date: Enhanced AppleScript Support in OS X 10.1
  • Previous by thread: Re: stack overflow error processing text file [relsit: can't
  • Next by thread: Re: stack overflow error processing text file [relsit: can't
  • Index(es):
    • Date
    • Thread