Re: Manipulating text
Re: Manipulating text
- Subject: Re: Manipulating text
- From: "Mark J. Reed" <email@hidden>
- Date: Sat, 26 Sep 2009 11:47:57 -0400
This is where what's going on behind the scenes matters. When a
variable holds a simple scalar value - number or string - it contains
the whole thing as it's value, and set copies that value. When a
varIable "holds" a list or record or date or other object, its value
is really just a pointer to the actual structure. So when that value
is copied, you just get another variable pointing to the same object,
not a new copy of the object. using "copy" causes the whole thing to
be duplicated and the target variable pointed at the copy.
On Saturday, September 26, 2009, Jon Pugh <email@hidden> wrote:
> [Reply directed to the list]
>
> At 8:16 AM -0400 9/26/09, Doug Tallman wrote:
>>I'm sure this is painfully obvious to some, but I'm not sure I see the reason ...
>>
>>why:
>>
>> copy "0123456789ABCDEF" to hConst
>>
>>and not
>>
>> set hConst to "0123456789ABCDEF"
>>
>>
>>In other words, when do you use "copy" and when "set"
>
> It'a not painfully obvious, in fact it's downright obtuse and has confused people since the dawn of AppleScript.
>
> In this case, with literal data, they are the same. You can use either.
>
> However, when using lists which can share data via references/pointers, set can share data, while copy always duplicates. In those sorts of situations, you need to use the one that makes sense.
>
> I don't know why I used both here, other than random chance and the fact that it doesn't matter in this instance.
>
> Other scripting languages use text for all data, while AppleScript uses many data types, including pointers as references, and as such it has more complex data management and handling than if it could only pass text around. This is, like most things, both good and bad.
>
> The guy who wrote this part of AppleScript was bothered by the similarity and differences, but couldn't see any way to avoid it. Sometimes set and copy are the same, when data cannot be shared, and sometimes they're different, when data can be shared.
>
> Most of the time it doesn't matter, unless it does. ;)
>
> Jon
> _______________________________________________
> 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
>
--
Mark J. Reed <email@hidden>
_______________________________________________
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