Re: list question
Re: list question
- Subject: Re: list question
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 04 Jun 2003 08:05:10 -0700
On 6/4/03 7:04 AM, "Michelle Steiner" <email@hidden> wrote:
>
On Wednesday, June 4, 2003, at 03:08 AM, Chris Page wrote:
>
>
>> OK, I see it now. the variable (what it is a reference to) can be
>
>> changed, but the item being referenced can't, unless it is mutable.
>
>
>
> And I would say it this way: The variable can be bound to a different
>
> object, but the object it is bound to can't be altered unless it is
>
> mutable.
>
>
*nod*
>
>
So, when the script says set a to a & "A", the result is that a
>
references a different object than before, right?
Right. It's a new assignment of the variable a to a different object.
This stuff gets interesting when you look at it very closely. Because
strings are not mutable, everyone understands that you cannot say
set "a" to "b"
So when you say
set a to "a"
set a to "b"
that means that what you are doing is re-assigning (binding) the variable
a to a new object. It's the fact the the language itself pre-defines
strings as non-mutable which determines that 'set a to "b"' is doing a
reassignment, and that the statement can only mean this one thing. Yet
set a to {"a"}
set a to {"b"}
really does mean:
set {"a"} to {"b"}
Try it: you can run that last statement on its own with no error in a script
editor. It does not mean that "a" is being set to "b" any more than in the
first example. It's just saying you can change a list, because lists are
mutable, even where you haven't assigned a variable to the list. So it's the
pre-definition of lists as a mutable in the language which determines that
'set' here is changing the object itself, not doing a re-assignment.
The language itself must have this sort of prioritization built in as well.
I.e., it determines how the command 'set' is being used in any given
situation. If 'set' is being applied to a mutable object, then 'set' means
"change the object". Only where that meaning is impossible, because an
object (such as a string) is immutable, or because you haven't yet assigned
it to any object, does 'set' mean "re-assign this variable to a new
object". It's implicit, but requires you to know that strings are immutable
and lists are mutable to know what 'set' is going to mean in a given
situation.
That's what Doug was complaining of, in a way. Some languages would not use
'set' to mean two different things. But it's not such a big deal to learn
that strings are immutable while lists aren't. It is spelled out in the AS
Language Guide.
This issue also crops up in application dictionaries. Sometimes setting a
variable to an application keyword is dynamic, and changes when the
application object represented by the variable changes. And sometimes it's
static - the variable just keeps that first value even when the application
object changes, unless you specifically reassign it. Usually (always?) it is
only static when the application term resolves to a string or number or
other immutable AppleScript value, as many application objects do. But when
the result in a script editor is given as an application term (e.g. 'word 1
of paragraph 3 of document 1' rather than "The") then it will be dynamic:
the variable will change its value if you are able to change the object it's
pointing to.
--
Paul Berkowitz
_______________________________________________
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.