• 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: email@hidden (Michael Sullivan)
  • Date: Wed, 3 Oct 2001 17:50:15 -0400
  • Organization: Business Card Express of Connecticut

> 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.

I'm not sure I get what this means. By sub-bit are you referring to a
parse unit?

> 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.

So if one wanted to modify x, one would need to add:

set x to result

or similar. It makes sense. Interesting that it's AS's "intuitive"
syntax that lends to this confusion. If the contents of "function" were
called like so:

set end of contentsOf(x) to 3

It would be pretty obvious that you're trying to assign to a temporary
object.

Thanks for the tip on one-level worth of evaluation. I haven't run into
that problem yet, but I'm bound to someday, and you just saved me an
hour or two of trial and error testing at least.

--
Michael Sullivan email@hidden
Business Card Express of Connecticut Thermographers to the Trade
"You hate your job -- why didn't you say so? There's a support group
for that. It's called everybody; they meet at the bar." -Drew Carey


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

  • Prev by Date: Re: AS adoption barriers (starter kit)
  • Next by Date: Re: Creating list references in handlers. Bad code or bug?
  • 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