RE: "a reference to"
RE: "a reference to"
- Subject: RE: "a reference to"
- From: Scott Babcock <email@hidden>
- Date: Fri, 25 Jan 2008 15:01:08 -0800
- Acceptlanguage: en-US
- Thread-topic: "a reference to"
> The [ASLG] section on the 'a reference to' operator indicates that AppleScript's 'reference' type has a 'contents' property.
Yes, and it also states that it has a [class] property whose value is always 'reference'. The property-vs.-operator question can't even be resolved by looking at the 'aeut' resource in AppleScript.rsrc, since it shows neither a [contents] property nor a 'contents of' operator. This tends to suggest that "contents" is implemented through special-case handling, making its behavior more difficult to pin down, resembling both property and operator.
> > 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.
The ASLG doesn't list 'contents of' along with the rest of the operators, but it does refer to it as such in another section. Whether "contents" is a property or an operator, the end result is the same. Whatever the case may be, the ASLG is incomplete and/or imprecise on the subject.
As you indicate, the shallow-copy behavior of "contents" is undocumented and therefore subject to change without notice. I can't think of a good application for this behavior, anyway, so I'm not likely to use it intentionally.
I think we've taken this topic farther than it warrants. I hope I'm not the only one who found the discussion to be interesting and instructive.
-----Original Message-----
Date: Thu, 24 Jan 2008 23:51:02 +0000
From: has <email@hidden>
Subject: Re: "a reference to"
To: Applescript Users <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
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