Re: "a reference to"
Re: "a reference to"
- Subject: Re: "a reference to"
- From: has <email@hidden>
- Date: Thu, 24 Jan 2008 23:51:02 +0000
On 24 Jan 2008, at 22:00, Scott Babcock wrote:
Is "contents" a property or an operator? The ASLG is inconclusive.
The ASLG doesn't list it as an operator, which seems clear enough to me.
In addition to the [contents] property, the description of the
'reference' class indicates that a reference has a [class] property
whose value is always 'reference'. This is clearly wrong.
Yep.
Also, check "NOTES" under "Repeat With (loopVariable) In (list)":
"... you must use the 'contents of' operator:"
Another mistake. The section on the 'a reference to' operator
indicates that AppleScript's 'reference' type has a 'contents' property.
You can't [dereference] something that isn't a reference.
This is precisely my point. recordRef is clearly a reference,
because changes applied to it affect the corresponding list item
from which it derives.
Let's clarify again:
The 'recordRef' identifier is NOT bound to an AppleScript reference
object; it's bound to a record object. That same record object also
occupies the first slot in the list object that's bound to the
'theList' identifier.
As I said in an earlier mail, don't confuse the specific behaviour of
AppleScript's reference type with the behaviour of AppleScript objects
in general. AppleScript is a pretty standard object-based language
which - in terms of internal C/C++ implementation - means that all
AppleScript values are stack-allocated objects, and AppleScript
variables hold pointers to these stack-allocated objects (what C folks
call 'pass by reference'). Same deal as in Python, Ruby, Smalltalk,
etc. Note that such private details are irrelevant to end-users, who
should treat these languages' internals as a black box and stay on the
outside. I'm only mentioning it here because folks coming from lower-
level languages such as C sometimes have trouble initially wrapping
their heads around such languages until they understand what's
actually going on inside them at the C level.
From the user's point of view, you have first-class objects to which
you can bind any number of identifiers (what the ASLG, in its
typically unhelpful and non-standard way, likes to call 'data
sharing'). Thus, for example, if you bind two identifiers, 'foo' and
'bar' to a mutable object such as a list, you can refer to that list's
content via either of those identifiers:
-- bind 'foo' and 'bar' to the same mutable object
set foo to {}
set bar to foo
set end of bar to 1
foo
--> {1}
This is normal behaviour for object-based languages and has nothing
whatsoever to do with AppleScript's 'reference' type, e.g. here's the
same thing in Ruby:
foo = []
bar = foo
bar.push(1)
p foo
# [1]
It's clearly not a 'reference' object, since it can't be coerced to
'reference'. However, the 'contents of' operator creates a shallow
copy of the original record, a textbook example of dereferencing.
As I said before, asking a list or record for its 'contents' property
and getting a shallow copy as a result does not appear to be a
documented behaviour; therefore you should not read anything into it.
'Undocumented behaviour' = accidental, not to be trusted, do not use,
etc.
Also, if you're coming to AppleScript (or any other very high level OO
language) with a C-oriented mindset and jargon (which is what it
sounds like), don't. You will just confuse yourself.
has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden