Re: String to multiple-item list coercion
Re: String to multiple-item list coercion
- Subject: Re: String to multiple-item list coercion
- From: Steven Angier <email@hidden>
- Date: Sat, 21 Sep 2002 11:23:16 +1000
On 21/9/02 7:56 AM, "has" <email@hidden> wrote:
>
Steven Angier wrote:
>
>
> I may choose to live under a nice cosy rock, but I just learned that
>
> strings can be coerced to multiple-item lists:
>
>
>
> set {a, b, c, d, e} to "abcdefgh"
>
> return {a, b, c, d, e}
>
> --> {"a", "b", "c", "d", "e"}
>
>
This isn't a coercion, it's a multiple assignment. Comparable to:
>
>
set {a, b, c, d, e} to {"a", "b", "c", "d", "e", "f", "g", "h"}
No, it's a coercion, THEN a multiple assignment. (How do you suppose you got
an a list of characters to assign in the first place?)
>
> Similarly, one can now query a particular item of a string:
>
>
>
> item 5 of "abcdefgh"
>
> --> "e"
>
>
Again, not a new behaviour. Not too dissimilar to 'character 5 of
>
"abcdefgh"'. Both strings and lists are composite [multi-item] objects.
>
Think of a string as an array of characters
C forces me to think of strings as arrays of char, which I abhor.
Fortunately, AppleScript (and Cocoa with its NSString class) abstracts that
ugliness away -- or at least it is supposed to.
>
- I think it makes sense for
>
string and list types to display some behaviours in common. For example,
>
consider:
>
>
repeat with aChar in aString
>
...
>
end repeat
This is another example of the same bug (assuming that aString is a string).
>
> The ASLG (v1.3.7) indicates that this shouldn't work.
>
>
Does it mention it at all? (I could see 'characters of...', etc. described,
>
but I only had a quick flick-through. Did I miss something specific?)
Page 83 of the ASLG (v1.3.7) states "AppleScript also supports
coercion of a string to a single-item list...". Also, the coercion matrix on
page 364 indicates that strings cannot be coerced into multiple-item lists.
Steven Angier
Macscript.com
_______________________________________________
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.