• 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: Nested list multi - set
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Nested list multi - set


  • Subject: Re: Nested list multi - set
  • From: Chris Nebel <email@hidden>
  • Date: Fri, 29 Dec 2000 23:24:24 -0500
  • Organization: Apple Computer, Inc.

SemiColon wrote:

> I was staring at a couple of lines of code today trying to combine
> them into a multi - set, (set {a, b, c,} to {1, 2, 3} sort of thing).
> It turned out to need an array rather than a list, but I tried and
> found that it worked. My example would mean nothing out of the
> context of a largish script, but this example is similar.
>
> set {{a, b, c, d, {x, y, z}, e}, {f, g, h}, twee} to {{1, 2, 3, 4, {9, 10, 11}, "A"}, {6, 7, 8}, "deedle"}
> --> {{1, 2, 3, 4, {9, 10, 11}, "A"}, {6, 7, 8}, "deedle"}
>
> I didn't know that!

It's a feature -- see pp. 159-160 of the updated AppleScript Language Guide. The ASLG calls them "variable
patterns," though I originally learned this type of thing by the name "simultaneous assignment." The
assignment will work as long as the right- and left-hand sides match up.

Another interesting thing about variable patterns in AppleScript is that the assignments effectively take
place in parallel. For example, saying "set {a, b} to {b, a}" will swap the values of a and b. Try that
without an explicit temporary in most other languages, and you'll just set a to b, or b to a, depending on
how you order things.


--Chris Nebel
AppleScript Engineering


References: 
 >Nested list multi - set (From: SemiColon <email@hidden>)

  • Prev by Date: Re: How to move icons on desktop
  • Next by Date: Re: How to move icons on desktop
  • Previous by thread: Nested list multi - set
  • Next by thread: Re: How to move icons on desktop
  • Index(es):
    • Date
    • Thread