Re: Nested list multi - set
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