Re: String to multiple-item list coercion
Re: String to multiple-item list coercion
- Subject: Re: String to multiple-item list coercion
- From: has <email@hidden>
- Date: Tue, 24 Sep 2002 22:20:08 +0100
Steven Angier wrote:
>
>>>> set {a, b, c, d, e} to "abcdefgh"
[...]
>
> we never see a
>
> list of characters ourselves - and visible signs to suggest it doesn't - ie:
>
>
>
> set {a, b, c, d, e} to "abcdefgh"
>
> --> "abcdefgh" -- no change here
>
>
What were you expecting to see changed?
If the string were being cast to a new type (list), I might have expected
to see the result of that cast returned from the statement. Things that
happen generally seem to happen on the right-hand side, and the results of
right-hand operations get assigned to AS's 'result' variable as well:
set x to 2 + 3
get result
--> 5
If there _is_ some sort of coercion operatiom happening, it must be
happening on the left-hand side, but I can't think of any other situation
where anything fancy happens on the left [1].
And all this seems a rather difficult explanation, compared to saying it's
a common or garden multiple assignment. A multiple assignment is basically
shorthand for several single assignments:
set tempVar to "abcdefgh"
set a to first item of tempVar
set b to second item of tempVar
set c to third item of tempVar
set d to fourth item of tempVar
set e to fifth item of tempVar
i.e. 'a' is the first item of the left-hand object, so gets the first item
of the right-hand object assigned to it; 'b' is the second item of the
left-hand object, so gets the second item of the right-hand object assigned
to it; etc. [2]
It doesn't seem unreasonable that any type that knows what an 'item' is can
be used in a multiple assignment. Strings know what 'item' is, therefore
strings I see no reason why they shouldn't work here without need for any
extra magic.
>
It's not in keeping with the documentation.
What's new? :p
If you think that 'item x of str' is a bug, perhaps you should submit a bug
report on that. I don't honestly imagine the AS team wanting to change the
current behaviour (it doesn't seem inappropriate; an 'item' is the smallest
functional unit, which is a character here; besides think of the stink
removing this behaviour would raise from folk who already use it), but
perhaps they'd hurry up and update a supposedly "canonical" reference guide
that's trailing by several years and several major AS versions.
Cheers,
has
[1] (unless anyone else knows of any)
[2] Assignments, yes? Or is the following a coercion too:
set {day:a, month:b, year:c} to date "Sunday, September 1, 2002 12:00:00am"
return {a, b, c}
--> {1, September, 2002}
?
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
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.