• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "a reference to"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "a reference to"


  • Subject: Re: "a reference to"
  • From: deivy petrescu <email@hidden>
  • Date: Thu, 17 Jan 2008 17:18:21 -0500


On Jan 17, 2008, at 13: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. 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.

As you noted, I didn't save the result of the coercion in any way that the script could use; I merely logged the error message if it failed. I could have set an isRef variable to 'true' or 'false', but I didn't need to since the behavior of the script didn't vary based the inferred type of thisItem.

The thing that puzzles me is that the behavior of the script indicates that thisItem must be a reference, yet the 'reference' coercion still fails. I guess this is what Matt meant when he stated that techniques for identifying references "seem *mostly* to work."

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 {theList, itemRef, recordRef, localItem}
end repeat
--> {{{foo:"ref"}}, {item 1 of {{foo:"ref"}}, {foo:"ref"}, {foo:"local"}}


This result clearly shows that recordRef is a reference to the original record in theList, whereas localItem is merely a local copy.


Scott
I got you now!
Actually using has handler and your script, I understand you puzzlement.
I think, however, that "thisItem" in your original script is a reference.
Not that this does not come without pain. A similar situation, actually analogous to records is:
----1-----
set l to {{1}, {2}, {3}}


repeat with j in l
	set k to contents of j
	set item 1 of k to 2 * (item 1 of k)
end repeat
l
-->{{2}, {4}, {6}}

or its synonym:
-------2------
set l to {{1}, {2}, {3}}

repeat with j in l
	set k to get j
	set item 1 of k to 2 * (item 1 of k)
end repeat
l
-->{{2}, {4}, {6}}

and  finally this:
-------3------
set l to {1, 2, 3}

repeat with j in l
	set k to contents of j
	set contents of j to 2 * (contents of j)
end repeat
{l, k}
-->{{2, 4, 6}, 3}

1 and 2 plus your original script show that it is a reference. Script 3 shows it is a tenuous reference. Once anyone of the two is "reset" the reference is gone.
Again, it does not come without pain...
But it would not be fun otherwise, would it?


Deivy
_______________________________________________
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
References: 
 >RE: "a reference to" (From: Scott Babcock <email@hidden>)

  • Prev by Date: Re: Get only the name of the file, instead of the whole path!
  • Next by Date: Re: Question on a script
  • Previous by thread: Re: "a reference to"
  • Next by thread: Re: "a reference to"
  • Index(es):
    • Date
    • Thread