Re: List Behavior
Re: List Behavior
- Subject: Re: List Behavior
- From: Christopher Nebel <email@hidden>
- Date: Wed, 5 Mar 2008 13:34:22 -0800
On Mar 5, 2008, at 11:52 AM, Steven D. Majewski wrote:
On Mar 5, 2008, at 2:38 PM, John Mistler wrote:
I have discovered some peculiar behavior with lists. Can anyone
help me understand why?
This works as expected:
set a to {{1, 2, 3}, {"x", "y", "z"}}
set b to item 1 of a
set c to item 1 of a
set c to c & {4}
log b --> {1,2,3}
log c --> {1,2,3,4}
but why does this happen?:
set a to {{1, 2, 3}, {"x", "y", "z"}}
set b to item 1 of a
set c to item 1 of a
set end of c to 4
log b --> {1,2,3,4}
log c --> {1,2,3,4}
Both work as expected (or as they should be expected to).
'set c' binds the name c to an object.
Evaluation of the new object happens before the binding,
so the "c & {4}" on the right-hand-side refers to the old binding.
"b" is still bound to that first object, so "b" and "c" name
two different objects.
'set end of c' is modifying the object named c by changing the end.
You haven't changed what "b" or "c" point to, but you've changed
the value of that thing by changing it's "end" .
Or, put a bit differently:
Because you used "set" in the first two assignments, b and c both
refer to the same object (which is a list {1, 2,3}). This means that
modifications to that object will be visible through both variables --
try setting one of the items to see the effect. Compare "copy", which
creates an independent copy of its source.
The "&" operator creates a new object for its result, so "set c to c &
{4}" doesn't change the original list (which is still bound to b), it
makes a new list {1, 2, 3, 4} and binds that to c. "set end of...",
however, modifies the original object, so you see the change in both
places.
--Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden