RE: "a reference to"
RE: "a reference to"
- Subject: RE: "a reference to"
- From: Scott Babcock <email@hidden>
- Date: Wed, 16 Jan 2008 14:50:46 -0800
- Acceptlanguage: en-US
- Thread-topic: "a reference to"
Here's a bit of code that still mystifies me, although I can get it to do what I want:
set foo to {{foo:"foo1"}, {foo:"foo2"}}
repeat with itemRef in foo
try
itemRef as reference
on error errmsg
log errmsg
end try
-- de-reference list-item reference
set thisItem to (contents of itemRef)
try
thisItem as reference
on error errmsg
log errmsg
end try
-- set value of record property
set fooVal to (foo of thisItem)
set foo of thisItem to "bar" & (text -1 thru -1 of fooVal)
end repeat
get foo
If you run this script, you'll see that the final result shows that the values of the [foo] properties of the items within the original list have been altered. This means that [thisItem] must contain a reference to the original record instead of being a local copy. However, the event log shows that the 'reference' coercion fails:
(*Can't make {foo:"foo1"} into type reference.*)
Further, if you de-reference itemRef twice (i.e. - contents of contents of itemRef), the contents of the original list of records remains unaltered. This double de-reference causes the code within the 'repeat' loop to operate on local copies.
-----Original Message-----
Date: Tue, 15 Jan 2008 22:50:25 -0500
From: "Gary (Lists)" <email@hidden>
Subject: Re: "a reference to"
To: AppleScript Users <email@hidden>
Message-ID: <C3B2E931.4FE9%email@hidden>
Content-Type: text/plain; charset="US-ASCII"
"deivy petrescu" wrote:
> I assume that "get" came together with cocoa or OS X. I am sure that
> in 9.xx and earlier I have not used get. Or I've used it sparingly. I
> do not recall "somethingelse of (get something)" before X, but can
> assure you that in X it became "get somethingelse of (get something)"
I am not up to speed on the inner workings of, well, anything, frankly, but
in Smile, even before OSX, it has been needed to use "get" quite regularly.
If my memory serves, it was explained to me that Smile's retention of the
global context (remembering variables across script windows, and even across
launches if the user does that intentionally) had something to do with this
need.
Perhaps Smile's interaction with AS at some lower level made it necessary to
"expose" this need at the higher scripting level.
All of that to say that I don't think this need to use an explicit 'get'
came with OSX, but perhaps OSX did change silent dereferencing in some way.
<shrug>
(And perhaps Emmanuel can tell us something about why Smile has, for some
time, needed explicit 'get' statements more than, say, Script Editor.)
--
Gary
_______________________________________________
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