Re: list question
Re: list question
- Subject: Re: list question
- From: Andrew Oliver <email@hidden>
- Date: Wed, 04 Jun 2003 13:49:28 -0700
Assuming there's a question here as to why this works and doesn't throw an
error...
What you're seeing here (or not seeing, as the case may be ;) is
AppleScript's automatic coercion of variables.
Since you asked for "a + b", the plus sign indicates numeric addition, so a
and b are coerced to numbers and then added together, resulting in 5 which
you then further coerce back to a string.
If you wanted the result of "32" you'd need to use & to concatenate the
strings together.
In either case, it still doesn't violate the mutable rules since you
(re)define a when you:
set a to "3" as string
Meaning a no longer points to the same object as b
What I think you're ultimately trying to get to is:
set a to {3}
set b to a
set c to a + b
--> 6
since a is a mutable object (a list), you can:
set item 1 of a to 4
set c to a + b
--> 8
In this case you're setting the contents of the object referred to by 'a' to
a new value. Since b points to the same object it appears to change value,
too.
However, the old rule still applies in that if you:
set a to 5
set c to a + b
-->9
because you set a to point to a new, distinct object with the value of 5,
separate from the object that b is still pointing to (which still has a
value of {4}).
Andrew
:)
On 6/4/03 1:17 PM, "Doug McNutt" <email@hidden> wrote:
>
set a to "2" as string
>
set b to a
>
set c to a + b as string
>
c
>
--> "4"
>
set a to "3" as string
>
set c to a + b as string
>
c
>
--> "5"
>
_______________________________________________
>
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.
_______________________________________________
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.