Re: Deleting last item of a List
Re: Deleting last item of a List
- Subject: Re: Deleting last item of a List
- From: kai <email@hidden>
- Date: Sat, 20 Nov 2004 01:28:03 +0000
On Nov 19, 2004, at 4:00 PM, Nigel Garvey wrote:
set x to end of myList -- get the last item in the list
set x to last item of myList -- ditto
(For some reason, the former executes more quickly.)
Later, on Fri, 19 Nov 2004 23:07:46 +0000, Nigel then wrote:
My rough guess for why getting the end of a list is faster than
getting its last item is that AppleScript doesn't need to check that
the last item is actually an 'item'. :-) Rather in the same way that
counting a list is faster than counting its items.
That would be about my take on it too, Nigel.
If one takes a single object (such as a string) that is not itemised as
a list, then 'end' will produce an error number -1728
(errAENoSuchObject) [1] - suggesting that AppleScript has not checked
for items:
------------------------
set myString to "abc"
end of myString
--> error: Can't get end of "abc".
------------------------
However, the following *does* work - indicating that some
check/implicit itemisation takes place:
------------------------
set myString to "abc"
last item of myString
--> "c"
------------------------
---
kai
[1] To get something like 'end' to work here, it's necessary to
explicitly coerce myString to a list of its items/characters, words,
paragraphs or text items:
------------------------
set myString to "abc"
end of myString's items
--> "c"
------------------------
(The coercion makes this evaluation slower than 'last item of
myString'.)
---
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden