RE: AppleScript-Users Digest, Vol 5, Issue 37
RE: AppleScript-Users Digest, Vol 5, Issue 37
- Subject: RE: AppleScript-Users Digest, Vol 5, Issue 37
- From: Scott Babcock <email@hidden>
- Date: Thu, 17 Jan 2008 17:46:28 -0800
- Acceptlanguage: en-US
- Thread-topic: AppleScript-Users Digest, Vol 5, Issue 37
No, I mean a reference to *any* object. The word "reference" is far too overloaded for my taste. AppleScript has a 'reference' data type, but it appears also to play with references of another sort, one that it hides.
Here's the example again:
set theList to {{foo:"foo"}}
repeat with itemRef in theList
set recordRef to (contents of itemRef)
set foo of recordRef to "ref"
set localItem to (contents of recordRef)
set foo of localItem to "local"
return {itemRef, recordRef, localItem}
end repeat
--> {item 1 of {{foo:"ref"}}, {foo:"ref"}, {foo:"local"}}
* recordRef is a reference to the record that is item 1 of theList. This is demonstrated by the fact that the change to the [foo] property of recordRef is reflected in theList.
* localItem is merely a copy of the original record. Changes to its [foo] property do not affect either theList or recordRef.
>From this behavior, I infer that list items with non-primitive data types (lists, records, application objects) are stored in the list as references. This makes sense, since it means that complex items in the list are no more difficult to manage than primitive items. However, these references are apparently not presented as 'reference' objects; they seem to be of some internal data type.
-----Original Message-----
Date: Thu, 17 Jan 2008 20:09:48 +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 17 Jan 2008, at 18:57, Scott Babcock wrote:
> Sorry... I failed to explain the purpose of the 'reference'
> coercion. This code is derived from "AppleScript: The Definitive
> Guide" by Matt Nueburg, in the section titled "Identifying
> References".
>
> AppleScript provides no direct way to determine that it's handed you
> a reference instead of a local object.
References are local objects [1]. I assume you mean 'references to
application objects'.
> One of the workarounds for this deficiency is to attempt to coerce
> the item in question to 'reference'. Since non-reference items
> cannot be coerced to 'reference', the absence of an error gives
> indirect evidence that an item is a reference.
Personally, I'd do something like:
on isReference(obj)
return (count {obj} each reference) > 0
end isReference
Bear in mind that neither technique will distinguish between
references to local objects and references to application objects, e.g.:
isReference("Hello World") --> false
isReference(document 1 of application "TextEdit") --> true
isReference(a reference to item 1 of {1, 2, 3}) --> true
Things are rather more straightforward in appscript, FWIW, since all
the standard instance methods are kept unchanged, e.g.:
#!/usr/bin/ruby
require 'appscript'; include Appscript
obj = app('Finder').home.get
p obj.is_a?(Appscript::Reference) # true
obj = app('Finder').home.name.get
p obj.is_a?(Appscript::Reference) # false
has
[1] Of type 'reference', funnily enough, although as you say there's
no way to obtain that information directly since they're designed to
be largely transparent in their behaviour.
--
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