• 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: set myList to myList & ...(Applescript-users Digest, Vol 2, Issue 489)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: set myList to myList & ...(Applescript-users Digest, Vol 2, Issue 489)


  • Subject: Re: set myList to myList & ...(Applescript-users Digest, Vol 2, Issue 489)
  • From: Jonathan Levi MD <email@hidden>
  • Date: Tue, 26 Jul 2005 17:00:55 -0400

Message: 2
Date: Mon, 25 Jul 2005 21:44:38 +0200
From: Emmanuel <email@hidden>
Subject: Re: set myList to myList & ... and unexpected results
To: email@hidden
Message-ID: <p06002003bf0af145f9cb@[10.0.1.5]>
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

At 4:37 PM +0100 7/25/05, has wrote:

Michael Sullivan wrote:

>>>It's a bug, file a report. The first concatenation returns the right-hand
>
This isn't a bug, it's a feature :)

No, you've misread the problem. This has nothing to do with set vs copy. It's about the concatenation operator not returning a new object in certain situations. Example:

>set l to {1}
set a to l & {}
>set b to {} & l
set c to {0} & l

>set l's item 1 to 2
log a --> {1}
>log b --> {2} -- Wrong! Should be {1}
log c --> {0, 1}

I vote "bug". Category: "big"

No, it isn't. Per AppleScript Language Guide, p. 160:

 If you use the Set command to set a variable to a list, record, or
 script object, the  variable shares data with the original list,
 record, or script object. If you change the data of the original, the
 value of the variable also changes. Here's an  example of how this
 works:

 set myList to { 1, 2, 3 }
 set yourList to myList
 set item 1 of myList to 4

 The result of these statements is that item 1 of both myList and
 yourList is 4.

 Data sharing promotes efficiency when using large data structures.
 Rather than  making copies of shared data, the same data can belong
 to multiple structures.

In other words, "set" uses _reference(s)_ to the "rvalue(s)", by design rather than chance, in the interest of "efficiency."


Because you've set b by reference, rather than by value, what you see from the log command is the value of the reference at the time of the log command, rather than at the time of the set command. The way to avoid this use of references is to use the copy command, which makes an actual, new copy of the object:

set l to {1}
copy {} & l to b
set l's item 1 to 2
log b --> 1

BTW, logging strips braces; be aware of this if your object has complex structure and you want to see that structure as well as the data:

set l to {1}
{l, l}--result: {{1}, {1}}

But

set l to {1}
log {l, l}--Event log: (*1, 1*)

Jonathan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: set myList to myList & ...(Applescript-users Digest, Vol 2, Issue 489)
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: Really dumb question . . .
  • Next by Date: Re: Applescript-users Digest, Vol 2, Issue 490
  • Previous by thread: Re: passing a parameter to the run handler
  • Next by thread: Re: set myList to myList & ...(Applescript-users Digest, Vol 2, Issue 489)
  • Index(es):
    • Date
    • Thread