Re: A reference to
Re: A reference to
- Subject: Re: A reference to
- From: Christopher Nebel <email@hidden>
- Date: Thu, 7 Jun 2001 22:35:40 -0700
On Monday, June 4, 2001, at 04:26 AM, Charles Arthur wrote:
Bryan Harris <email@hidden> wrote:
Michelle wrote:
I understand the difference between "set a to b" and "copy b to a" but
don't understand what "set a to a reference to b" does.
I know that when you make a reference to a list, you can access that
reference much more quickly than accessing the list itself.
The difference is to do with stack pointers , I'm pretty sure...
Chris et al can feel free to leap in with a cluestick or cluebaseballbat
but my understanding would be...
I recently discovered the term "clue-by-four." I like it. (See
<
http://www.tuxedo.org/~esr/jargon/html/entry/clue-by-four.html> for
full details.)
"A reference to" in AppleScript actually behaves quite differently from
a pointer in C-like languages. What it does is defer evaluation of the
expression until you ask for the contents of the reference; each time
you ask for the contents, the original expression is re-evaluated. This
is why "a reference to the end of some_list" always gives you the last
item of the list, no matter what you did to it in the meantime.
I don't know exactly why references have the performance characteristics
they do, but it seems to short-circuit some checking AppleScript
normally does for circular references. (Why these checks are there in
the first place is also something of a mystery to me.) In my mind, the
question is not "why are references fast", but rather "why are
non-references slow?" The "reference to" trick is completely un-obvious
and un-documented, and I'd rather have the normal case behave well if at
all possible.
The scheme you describe is apt for load-store architectures, but
AppleScript really doesn't work that way. (For one thing, it doesn't
have registers as such.) I have been looking at ways to improve list
performance, but that's in the future.
--Chris Nebel
AppleScript Engineering