• 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: Sifting a list sans loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sifting a list sans loop


  • Subject: Re: Sifting a list sans loop
  • From: has <email@hidden>
  • Date: Mon, 28 Jan 2002 19:02:50 +0000

Paul Berkowitz wrote:
>
>On 1/28/02 7:15 AM, "Arthur J Knapp" <email@hidden> wrote:
>
>> This works for almost any AppleScript type-class. One word
>> of caution: for a list of 5000 items, you might run into
>> AppleScript's upper limit for returning a list, approx 4050
>> some items or so:
>
>Ah. What's this, then? I think I (or rather a user) may have run into this.

It's the old problem of coercing a string to list, when the resulting list
will contain more than ~4000 items (aka another longstanding AS bug).

e.g. every item of "[a 5000 character string]" --> stack overflow error

AppleMods seems to be down at the moment (I believe poor Greg is having to
play Hunt The Host at the moment), so here's my everyTextItem() handler
extracted from everyItemLib for your pleasure and edification.

======================================================================

property mxBlckLn : 3600

on everyTextItem(theString)
try
set textItemCount to count theString's text items
if textItemCount < mxBlckLn then return theString's text items
set theList to {}
set endLen to textItemCount mod mxBlckLn
set blockCount to textItemCount - endLen
repeat with eachBlock from 1 to blockCount by mxBlckLn
set theList to theList & theString's text items eachBlock
[NO-BREAK]thru (eachBlock + mxBlckLn - 1)
end repeat
if endLen is not 0 then set theList to theList & theString's
[NO-BREAK]text items -endLen thru -1
theList
on error number -2706
set mxBlckLn to (mxBlckLn div 4) * 3
everyTextItem(theString)
end try
end everyTextItem

======================================================================
[And they say Mods are a Bad Thing...;]

Just use:

set theList to everyTextItem(theString)

instead of:

set theList to every text item of theString

and your stack overflow problems are forever at an end. Woo-hooh! (And
then, rather than complain to me that the damn thing is slower, complain to
Apple that they _still_ haven't fixed that damn bug yet!;p)

Or I can send the full mod itself to anyone that wants it while AM is down.

has


  • Prev by Date: Re: Main Event (?)
  • Next by Date: Re: solutions to scripting addition terminology confilicts [goi
  • Previous by thread: Re: Sifting a list sans loop
  • Next by thread: Re: Sifting a list sans loop
  • Index(es):
    • Date
    • Thread