Re: Creating list references in handlers. Bad code or bug?
Re: Creating list references in handlers. Bad code or bug?
- Subject: Re: Creating list references in handlers. Bad code or bug?
- From: Christopher Nebel <email@hidden>
- Date: Tue, 2 Oct 2001 18:27:39 -0700
On Sunday, September 16, 2001, at 01:19 PM, Victor Yee wrote:
Hmmm, is this a bug?
set x to {1, 2}
set end of x's contents to 3
x
--> {1, 2}
It is, as we say, "working as designed." There are two problems here:
one is that object specifiers for AppleScript internal objects (like
lists) are fully evaluated at each sub-bit. The second problem is that
"contents of x" doesn't give you x's actual live contents, it gives you
the contents of each item [1]. That means you're working with a copy of
the original data.
Therefore, saying "set end of x's contents to 3" generates a new list,
sets *its* end to 3 (which has no effect on x), and then completely
forgets about it. Yes, this is bizarre, but it's expected.
--Chris Nebel
AppleScript Engineering
[1] If that wasn't clear, consider this:
set x to 3
set y to {1, 2, a reference to x}
{y, contents of y}
--> {{1, 2, x of +script;}, {1, 2, 3}}
"contents of" is effectively applied to each item of the list, but only
one level deep, as this should demonstrate:
set x to 3
set y to {1, 2, a reference to x}
set z to {3, 4, a reference to y}
{z, contents of z}
--> {{3, 4, y of +script;}, {3, 4, {1, 2, x of +script;}}}