• 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: Still more strange things …
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Still more strange things …


  • Subject: Re: Still more strange things …
  • From: Christopher Nebel <email@hidden>
  • Date: Wed, 21 Jan 2004 13:17:17 -0800

On Jan 21, 2004, at 1:38 AM, Jean-Baptiste wrote:

I've encountered the following in a script :

set theArray to {}
repeat 4 times
set end of theArray to theArray
end repeat

--> {{, , , }, {, , , }, {, , , }, {, , , }}

What does it mean ?

(For those still confused, the result really looks like this:

{{..., ..., ..., ...}, {..., ..., ..., ...}, {..., ..., ..., ...}, {..., ..., ..., ...}}

...except that the "..." are ellipsis characters in real life. Insert ritual cursing of the list server here.)

Now then, to the actual problem: what the Sam Hill is going on here? The answer is that AppleScript allows recursive structures, such as lists that contain themselves as elements. It's impossible to print such a list in its entirety, since it has an effectively infinite depth, so AppleScript notices the recursion and clips it off with the ellipsis. (This feature was added in 1.6 -- it used to just go for some indeterminate but fairly large depth.) You created a four-item list where each item is the original list itself. This is extra-confusing, since there are no real items anywhere; perhaps this one will be clearer:

set x to {1, 2}
set item 2 of x to x --> {1, {1, ...}}

No one has ever found a practical use for this that I'm aware of, but that doesn't keep people from trying it occasionally. If nothing else, it's an interesting thought experiment. (By the way, the original script works fine for me on Panther. I have no idea what Axel's problem is/was.)


--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Still more strange things …
      • From: Axel Luttgens <email@hidden>
References: 
 >Still more strange things … (From: Jean-Baptiste <email@hidden>)

  • Prev by Date: Re: Still more strange things ?
  • Next by Date: Re: applescript and browsers
  • Previous by thread: Re: Still more strange things ?
  • Next by thread: Re: Still more strange things …
  • Index(es):
    • Date
    • Thread