Re: list question
Re: list question
- Subject: Re: list question
- From: Chris Page <email@hidden>
- Date: Tue, 3 Jun 2003 13:37:02 -0700
On Tuesday, Jun 3, 2003, at 10:38 US/Pacific, Paul Berkowitz wrote:
Read the AppleScript Language Guide's relevant section on lists and
records. Lists and records "share data"...
I've always found the ASLG's description of "sharing" a little
confusing and overly complicated, especially since it treats some
objects as "shared" and not others. I think a simpler way to look at
this is that variables refer to objects, and some objects are mutable
(the object can be changed).
When you 'set' a variable you're binding its name to an object.
Multiple variables can be bound to the same object. If you change a
mutable object, every variable sees the change, because they are all
bound to the same object.
Objects that aren't mutable can't be changed, so every variable that
refers to an immutable object obviously won't change unless it is bound
to another object.
To make a copy of a mutable object so you can change one copy and not
the other, use 'copy' instead of 'set'. You needn't bother copying
immutable objects, because they can't be changed.
Lists and records are mutable. Numbers, strings, and most (all?) other
AppleScript objects are not -- you must copy string contents to a new
object if you wish to work with a substring, for example.
--
Chris Page - Software Wrangler - Palm, Inc.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.