Re: Coerce string to string!?
Re: Coerce string to string!?
- Subject: Re: Coerce string to string!?
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 13 Feb 2002 11:25:03 -0800
On 2/13/02 9:47 AM, "JJ" <email@hidden> wrote:
>
I'm missing some basic concept here:
>
>
<START SCRIPT>
>
>
set Original_String to "String"
>
set | 1 string list | to {"String"}
>
>
| 1 string list |'s item 1 = Original_String
>
-- true (OK)
>
>
repeat with i in | 1 string list |
That's 'item 1 of {"String"}' - a reference (or pointer), not evaluated
yet.
>
class of i
>
--> string (OK)
That evaluates 'item 1 of {"String"}' to "String" before it gets its class.
>
class of Original_String
>
--> string (OK)
That evaluates the variable Original_String to "String" before it gtes its
class.
>
>
i = Original_String
>
--> false (??????????)
i is a reference ('item 1 of {"String"}'), whereas Original_String is
the string "String" itself. Not the same thing. The equals operator '=' is
extremely particular about such things, whereas other operators such as
'contains' are happy to evaluate the reference as they go along.
>
>
(i as string) = Original_String
>
-- true (OK)
That coerces the reference 'item 1 of {"String"}' to the thing it's
referencing, so now it's true.
>
end repeat
>
>
</END SCRIPT>
>
>
So, AS 1.3.7 says:
>
>
i ("String"), wich is a string, is not equal to Original_String ("String"),
>
wich is a string, too.
>
>
Why?
>
Because 'i' is NOT a string, it's a reference to a string. You can either do
the coercion, as above, or use the other type of repeat loopwhich always
does the dereferencing for you:
repeat with i from 1 to (count | 1 string list |)
set x to item i of | 1 string list | -- that de-references it
--> "String"
x = Original_String
--> true
end repeat
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.