Re: list question
Re: list question
- Subject: Re: list question
- From: Andrew <email@hidden>
- Date: Tue, 03 Jun 2003 14:15:30 -0400
On 6/3/03 12:02 PM, "dialup" <email@hidden> wrote:
>
Can anyone tell me if I'm thinking wrong with this? If I run this code:
>
>
------------
>
set a to {"a", 1}
>
set b to a
>
set a's item 1 to "b"
>
return b
>
>
--> {"b", 1}
>
------------
>
>
>
but shouldn't b be {"a",1}? I'm running this in AS 1.6 on OS 9.2.2
You're thinking -
set a to {"a", 1}
copy a to b
set a's item 1 to "b"
return b
This whole thing can get confusing. Array and list and things are always
accessed by reference in every language I know. It's a quirk that in most
languages compound objects end up being passed around as references or allow
one of their properties to be modified without creating a whole new object.
The main reason for that is most of the time a compound object like a list
or array (or struct in C or object in most languages) can get fairly big. If
you had to create a brand new object every time you wanted to modify it, it
would be slow and extremely memory in-efficient. What is done instead is
only the values that changed are modified so that way the object can be
modified without having to duplicate most of its fields.
At any rate, this memory/time saving behaviour usually ends up creating a
split between primitives (usually defined of as being numbers (floats ints
blah blah), strings (sometimes) and compound objects (sometimes just known
as plain objects, arrays, structs, lists, blah blah) in many languages.
Things can more fun when you start to mix in immutable objects like the java
String class.
In Applescript I think the logic is there's no way of modifying an int
without creating a new one it's technically consistent. If it was possible
to do something like this
set the value of a to 9
then we could change the value of a reference without changing the reference
itself..
so you could do
set a to 1
set b to a
set the value of a to the value of a + 1
return b
=> 2
well anyway...
_______________________________________________
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.