• 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 make . . .]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: stack overflow error processing text file [relsit: can't make . . .]
  • From: monk <email@hidden>
  • Date: Tue, 17 Jul 2001 19:24:23 -0400

-- 7/17/01 07:04 pm: email@hidden said:

i also get a'stack overflow' on the similar script (optimized) below on the
line with: random number from 1 to pcount

in addition, i should note that i have been able, in a simple dirty early
version of the script to process the text file!?

<begin script>

set _source to open for access (choose file with prompt "choose source to
mix:") with write permission
set _mix to open for access file (((path to desktop) as string) & "mixed")
with write permission
--set mytext to read _source with delimiters {return, space} -- put
delimiters here.

set mytext to (read _source as list using delimiter {return, space}) -- this
is the equivalent of _source
set mymix to (read _mix as list using delimiter return) -- this is the
equivalent of _mix


mix(mytext, mymix) -- this mixes the original source into the new mix
set l to mix(mytext, mymix)
write l to _mix
close access _mix

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
is empty
end mix

close access _source

<end script>

h 'monk' elmer
--
http://www.assemblage.org
[ _ o
o o _ -- - - -- > s y m p h o n i c j a m s ]


>
> on the below script, which is working, i constantly get a 'stack overflow'
> error message and the line:
>
> mix(mytext, mymix)
>
> is highlighted in script editor
>
> the text file i'm trying to process is a simpletext file of 3,439 bytes, not
> huge by any means
>
> h 'monk' elmer
> --
>  %   %   %   % 
> http://www.assemblage.org
>  %   %   %   % 
>
>> -- 7/14/01 09:06 pm: email@hidden said:
>>
>> i got deivy's original working, and changed the tid here and there for
>> mixing items, added a write and close
>>
>> anyway though, i found that i always have 1 less item in the result than in
>> the source file, i.e., if the source has 8 items, the result will have 7,
>> and so on
>>
>> i don't mind randomly leaving out items, but is there a way to randomly
>> include all items too?
>>
>> thanks
>>
>> <adapted script>
>>
>> set _source to open for access (choose file with prompt "choose source to
>> mix:") with write permission
>> set _mix to open for access file (((path to desktop) as string) & "mixed")
>> with write permission
>>
>> set mytext to (read _source as list using delimiter {return, space}) -- this
>> is the equivalent of _source
>> set mymix to (read _mix as list using delimiter return) -- this is the
>> equivalent of _mix
>>
>> mix(mytext, mymix) -- this mixes the original source into the new mix
>>
>> on mix(mytext, mymix)
>> set zlist to {}
>> set text item delimiters to {space} -- change to get items, lines, or
>> 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
>> repeat with l from 1 to pcount
>> set zlist to zlist & l -- creating a list to take an element out of
>> end repeat
>> set k to contents of some item of zlist -- random element chosen
>> set mymix to mymix & text item k of mytext -- added to _mix
>> if k = pcount and k = 1 then --only one line in the _source, let's
>> finish it up
>> set mytext to ""
>> set mymix to rest of mymix
>> set mymix to mymix as string
>> set text item delimiters to "" -- restaure to default
>> return mymix
>> end if
>> if k > 1 and k < pcount then set mytext to (text items 1 thru (k - 1) of
>> mytext) & (text items (k + 1) thru pcount of mytext) as list
>> if k = 1 and pcount > k then set mytext to items 2 thru pcount of mytext
>> as list
>> if k = pcount and pcount > 1 then set mytext to text items 1 thru
>> (pcount - 1) of mytext as list
>> mix(mytext, mymix) -- using recurence. You want to do it until _source
>> is empty
>> end mix
>>
>> write result to file (((path to desktop) as string) & "mixed")
>> close access _source
>>
>> <adapted script>


References: 
 >stack overflow error processing text file [relsit: can't make . . .] (From: monk <email@hidden>)

  • Prev by Date: some vs. random no. [relsit: can't make . . .]
  • Next by Date: Re: can't make { . . . } into an item [error message] deivy's optimized example
  • Previous by thread: stack overflow error processing text file [relsit: can't make . . .]
  • Next by thread: Idle Question
  • Index(es):
    • Date
    • Thread