re List Question: Can someone explain this to me?
re List Question: Can someone explain this to me?
- Subject: re List Question: Can someone explain this to me?
- From: Charles Arthur <email@hidden>
- Date: Fri, 14 Jun 2002 11:37:37 +0100
On Fri, 14 Jun 2002 01:27:36 +0100, has <email@hidden> wrote:
>
Everybody gets caught by this one sooner or later. Me? I spent _three_ days
>
hard up against deadlines trying to track the problem when it bit me, so
>
consider yourself lucky by comparison. :)
>
>
See Data Sharing on p206-7 of ASLG. [1]
>
[1] BTW, while I'm not entirely sure, I do have a strong feeling the ASLG
>
explanation is really half-truth, half-fib. AFAIK, data is never copied in
>
AS unless explicitly instructed, thus 'set n to m' will mean a single
>
object is shared between both n and m regardless of its type.
No, I think the ASLG is glossing over the fact that it's cheap to fill
registers with data such as a number or text, but expensive to set up the
pointers required to follow a list (or record, or script object) around
memory. It's an assembler-level question.
If lists (records, script objects) were to behave like other simpler
classes, then you would do a lot of duplication in memory of lists (...),
which would mean that you'd be using up pointers like billyoh. Very hard to
keep track of. And likely to lead to all sorts of degradation of
performance.
So, one suspects, they decided to implement it in the method which would
occasionally produce gotchas such as tripped up has and Steve; but with the
tradeoff that it would operate more quickly, and use less instructions.
Clearly it's the sort of difference which must be explicity coded somewhere
in the innards of AS, unless it's a more system-wide symptom - do Mac
programmers elbow-deep in code get caught by this?
>
What really matters is whether the object in question is mutable or not;
>
i.e. whether or not you can modify its contents.
>
you can't do..
>
set s to "fool"
>
set item 3 of s to "a"
>
s --> "foal"
I think that begs the question. If simple data types behaved like this,
then you'd tailor the explanation in the way that fitted that.
Text, numbers or booleans are small pieces of data - a data store
and a pointer to that data store. Lists (...) are data store and a pointer
*and* pointers to where the next piece of linked data is with its
associated data store and pointer, with another pointer to the next
pointer. Etc. The overhead for a list, at the processor level, is much,
much bigger than it might appear from the easy way in which one can write
"{this, that, the, other}" - text, dead easy, very low overhead)
{"this", "that", "the", "other"} - list, very hard to set up efficiently.
To us humans the difference is just a question of quote marks and a bit of
abstract thought. To the machine, it's a whole load of chuntering about.
>
You can, however, change the content of complex data types such as lists,
>
records and scripts.
Yes. But I think these are symptoms of the underlying reason, rather than
reasons per se for the behaviour. It's because you can run along the index
of pointers to access the pointer to the data store to the particular piece
of content.
But you can't (in the list example above) do "set character 3 of
item 1 to "a" - as per your example of a simple string. Lists have bigger
overheads.
>
[As my high school
>
Biology teacher once told us: "We're going to teach you a lot of lies,
>
half-truths and gross over-simplifications in this subject, but as long as
>
you learn it all it'll get you through your exams just fine. Once you're in
>
university you can learn the real truth there."]
Yeah, though this is quintessential Apple. They just say what it does and
don't even begin to try to explain it. MSoft would probably refer you to
500 pages of incomprehensible gurglage. Or make it say in the error
message: "Could not complete operation because pointer 000ExF failed to
complete operation."
Charles
----------------------------
http://www.ukclimbing.com : 1100+ British crags, 350+ British climbing
walls - searchable by distance and anything else you care to think of -
with weather forecasts for every one, plus maps, articles, news and
features. And there's even a cool shop attached.
________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit
http://www.messagelabs.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.