• 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: Creating list references in handlers. Bad code or bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating list references in handlers. Bad code or bug?


  • Subject: Re: Creating list references in handlers. Bad code or bug?
  • From: Deivy Petrescu <email@hidden>
  • Date: Tue, 2 Oct 2001 22:35:22 -0400

At 6:27 PM -0700 10/2/01, Christopher Nebel wrote:
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;}}}

If you allow me to jump in, since I had a terrible weekend because of this question, about two weeks ago.
The problem is simpler.
If we say:
set x to 3
then x is a variable and 3 is a constant that I assigned to the variable.
x is a variable, that is, it can vary. 3 is a constant, that is *it can't vary.*
if I write now
set y to a reference to x
y is another variable, whose contents is x (another variable). However, x is a variable whose contents is 3, a constant. So:
set contents of y to x+1
is alright. I take a variable, x, the contents of y, and set it to what I want, x+1 in this case. After all x is a variable.
Now, if I try
set the contents of x to 4
I get an error, since the contents of x is a constant and *can not be set*. In other words AS will complain about the following
set 3 to 4
set end of {1,2,3} to 5
set last item of {2,3} to "a"
They are all the same problem, namely one can not set a constant.
Simpler but cause me some bad dreams...
Regards



--
Deivy Petrescu
http://www.dicas.com
Tips for Mac
dicas para Mac


References: 
 >Re: Creating list references in handlers. Bad code or bug? (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Re: repeat problem
  • Next by Date: Re: Is there a "wake up" detector?
  • Previous by thread: Re: Creating list references in handlers. Bad code or bug?
  • Next by thread: Re: Creating list references in handlers. Bad code or bug?
  • Index(es):
    • Date
    • Thread