Re: How do you check the equivalency of references?
Re: How do you check the equivalency of references?
- Subject: Re: How do you check the equivalency of references?
- From: Nigel Garvey <email@hidden>
- Date: Fri, 10 Aug 2001 14:29:38 +0100
At the beginning of this thread, Anthony described the difficulties in
determining whether or not the value of a variable was a reference or the
real thing. This handler may help, though it probably needs to be adapted
to cope with the long-string problem that's been mentioned (and possibly
with other problems that haven't occurred to me).
on isRef(val)
try
contents of val
return (result is not val)
on error
return false
end try
end isRef
Thus:
script anScript_Obj
property nada : ""
end script
set anObj_ref_A to a reference to anScript_Obj
{isRef(anScript_Obj), isRef(anObj_ref_A)}
--> {false, true}
One way to see if two variables ultimately refer to the same original
value (not necessarily the same original object) is to see if they
'contain' each other:
anScript_Obj contains anObj_ref_A and anObj_ref_A contains anScript_Ob
--> true
A faster way would be to coerce both variables to items and compare the
results directly, but this errors with variables that are references to
references.
This only partially addresses Anthony's problem, but it's offered for
what it's worth.
NG