Re: list question
Re: list question
- Subject: Re: list question
- From: Chris Page <email@hidden>
- Date: Wed, 04 Jun 2003 16:41:16 -0700
On Wednesday, Jun 4, 2003, at 08:05 US/Pacific, Paul Berkowitz wrote:
set a to {"a"}
set a to {"b"}
really does mean:
set {"a"} to {"b"}
No:
set a to {"a"} -- bind a to mutable list {"a"}
set b to a -- bind b to the same list
set a to {"b"} -- bind a to the mutable list {"b"}
{a, b}
--> {{"b"}, {"a"}}
The mutable list {"a"} is not altered.
The meaning of 'set' depends on what's between the 'set' and the 'to':
set a to 1 -- bind a to the immutable integer 1
set item 1 of {1, 2} to 3 -- mutate the mutable list {1, 2}
set item 1 of "AB" to "C" -- mutate the immutable string "AB"
set name of item 1 of app "Finder" to "Foo"
-- send a 'set data' event
In the first example, the left-hand side of the 'to' is a variable -- a
binding. All set ever does with bindings is bind them to the object on
the right-hand side of the 'to'.
In the second, the left-hand side is a specifier for the first item of
the mutable list {1, 2}. In this case, 'set' sets whatever is specified
(the first item of the list) to the right-hand side (3).
The third example is exactly the same as the second, as far as 'set' is
concerned. The left-hand side is a specifier for the first item of the
immutable string "AB", and 'set' tries to set it to "C", but this
produces an error because "AB" is immutable.
The important point here is that the meaning of 'set' isn't affected by
whether the specified object is mutable. 'set' tries to set the
specified left-hand side to the value of the right-hand side. It just
produces an error when 'set' attempts to alter an immutable object.
In the last example, the left-hand side is a specifier for an
application object. This means "send a 'set data' event to the
application named 'Finder'". Both the left and right-hand sides of the
'to' are sent in the event. Exactly what the application does with the
left and right-hand sides of the 'to' depends entirely upon the
application.
--
Chris Page - Software Wrangler - Palm, Inc.
Go to MacHack...or die trying: <
http://www.machack.com/>
_______________________________________________
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.