Re: "a reference to"
Re: "a reference to"
- Subject: Re: "a reference to"
- From: deivy petrescu <email@hidden>
- Date: Wed, 16 Jan 2008 22:04:57 -0500
On Jan 16, 2008, at 17:50, Scott Babcock wrote:
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.
Scott, I don't believe you are doing what you think you are doing.
itemRef as reference does not change it.
You can check that.
Try this;
set foo to {{foo:"foo1"}, {foo:"foo2"}}
repeat with itemRef in foo
set itemref1 to itemRef as reference
set itemref2 to (a reference to contents of itemRef)
return itemref1 = itemRef
end
---> true
now this:
set foo to {{foo:"foo1"}, {foo:"foo2"}}
repeat with itemRef in foo
try
set itemref1 to itemRef as reference
set itemref2 to (a reference to contents of itemRef)
on error errmsg
log errmsg
end try
return {itemRef, itemref1, itemref2}
end
-->{item 1 of {{foo:"foo1"}, {foo:"foo2"}}, item 1 of {{foo:"foo1"},
{foo:"foo2"}},contents of item 1 of {{foo:"foo1"}, {foo:"foo2"}}}
So, itemref2 is the one that is really a reference.
_______________________________________________
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