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 09:00:50 -0400
Hi monk,
>
hmmm . . . that is some interesting info. on applescript and handlers, i'm
>
not sure how to 'flatten'
Sorry, that's my own description. What I meant was to move the handler code inline with the rest of the script (I'm not sure if that made more sense).
>
tooling around with your suggestions for awhile now and here are the results
>
i get:
>
>
on a small file randomizing by word, i get many repeated incidents of the
>
first word chosen, in a row
>
>
on a large file (10k words) i get on errmsg, that the variable _listsource
>
is not defined
>
>
i tried changing and redefining the _listsource routine as victor suggested,
>
and elsewhere, to no effect
>
>
so, more confused than ever
>
>
oh well, guess i asked for it huh?
Oops, it was me that was confused. I didn't realise that "some" actually got the _contents_ of "some" item (i.e. dereferenced). That handler didn't work the way it was intended so you got repeated words.
Alright, this time I sat down and actually worked with the entire script. Try this and tell me if you run into problems or questions. The randomising uses Tim's code but with a modification to avoid using "random number". It may cause a memory problem with a 10,000 word source, but we'll see (I have to create a 10,000 word file to test it on).
My apologies for messing up.
Victor
-- start
set _source to (choose file with prompt "choose source to juxtapose:")
set _source to open for access _source
try
set _listsource to words of (read _source)
close access _source
on error
close access _source
end try
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
set _listcount to (length of _listsource)
set _indexlist to {}
repeat with i from 1 to _listcount
set end of _indexlist to i
end repeat
repeat with i from 1 to _fileamount
repeat with x from _listcount to 1 by -1
set current_item to some item of _indexlist's items 1 thru i
set temp to _listsource's item x
set _listsource's item x to _listsource's item current_item
set _listsource's item current_item to temp
end repeat
set text item delimiters to {" "}
set oldTIDs to text item delimiters
set _filename to "juxtatext " & characters -2 thru -1 of ("0" & i)
set _juxtatext to open for access file ("" & _newfolder & _filename) with write permission
try
write (_listsource as string) to _juxtatext starting at eof
close access _juxtatext
on error
close access _juxtatext
end try
set text item delimiters to oldTIDs
end repeat
set _listsource to {}
-- stop