Re: processing time & stack overflow
Re: processing time & stack overflow
- Subject: Re: processing time & stack overflow
- From: Victor Yee <email@hidden>
- Date: Tue, 28 Aug 2001 18:26:11 -0400
On Tue, 28 Aug 2001 11:05:04 -0400, Arthur J Knapp wrote,
>
on NewOrder(lst)
>
set {s1, s2, len} to ,
>
{random number from 1 to 100000, 31415, lst's length}
>
repeat with i from 1 to len
>
set {j, s1} to {(s1 mod len) + 1, (s1 * s2) mod len}
>
set {lst's item i, lst's item j} to ,
>
{lst's item j, lst's item i}
>
end repeat
>
end NewOrder
Thanks Arthur :)
After playing with this 'cross cutting' script for a while, I would have to conclude that having AppleScript very large lists isn't a good idea. In this case, it seems best to use it for what it's meant to be used for; as a means to make decisions and tell other applications to do the work.
Here's a script that uses Tex-Edit Plus that seems to scale well, although, perhaps not as fast as you'd like.
Victor
on _switchWords(a, b)
tell application "Tex-Edit Plus"
tell window 1
set x to text of word a
set contents of word a to text of word b
set contents of word b to x
end tell
end tell
return
end _switchWords
on _saveResult(thisFile)
tell application "Tex-Edit Plus"
tell window 1
save in file thisFile
end tell
end tell
end _saveResult
set _source to (choose file with prompt "choose source to juxtapose:")
tell application "Tex-Edit Plus"
open _source
set _wordcount to count of words of window 1
end tell
set _fileamount to "1"
repeat until class of _fileamount is integer and _fileamount > 0 and _fileamount < 100
try
display dialog "enter amount of files to generate from source (1-99)?" default answer _fileamount giving up after 12
set _fileamount to text returned of the result as integer
on error
display dialog "that wasn't the right kind of number!"
end try
end repeat
set _newfolder to (path to desktop as string) & "juxtatext(s)"
tell application "Finder"
--activate
if not (exists folder _newfolder) then
make new folder at desktop with properties {name:"juxtatext(s)"}
end if
open folder _newfolder
set size of window of folder _newfolder to {253, 527}
set view of window of folder _newfolder to kind
end tell
set _newfolder to (alias _newfolder) as string
repeat with x from 1 to _fileamount
repeat with a from _wordcount to 1 by -1
set b to random number from 1 to a
_switchWords(a, b)
end repeat
set _filename to "" & _newfolder & "juxtatext " & characters -2 thru -1 of ("0" & x)
_saveResult(_filename)
end repeat