arraylast( in theory
Robert Ameeti
robert at fastrak.biz
Sat Feb 23 09:27:22 PST 2008
At 11:51 AM -0500, 2/23/08, James Cook wrote:
>I don't know if it's a bug or not, but I would expect that arrylast(
>would respond much as a regular array( if there is no more than a
>single element in an array.
>
>Take the string "abcd"
>
>array( "abcd",1,".") returns "abcd"
>array( "abcd",2,".") returns ""
>arrayfirst( "abcd",".") returns "abcd"
>arraylast( "abcd",".") returns "abcd"
>
>I would expect arraylast( to return "" although I can see all the
>arguments for otherwise.
Huh? Why would you expect arraylast( to return "" when the last
element is 'abcd'? The first element is 'abcd', the last element is
'abcd', and no element is "".
>But consider:
>extract( "abcd",".",1) returns "abcd"
>extract( "abcd",".",2) returns ""
>"abcd" [1,"."] returns "abcd"
>"abcd" [".",-1] returns ""
>
>So the theoretically based question is, if there is one or no element
>in an array, does the array actually have a last element, or is the
>last element empty?
An array always has a first and a last element. The first element,
and the last element can be empty or they can have data.
>Array sizes can vary a lot from nothing to many elements.
I don't think so. I think every array has at least one element. It
may be empty. It will always have a first and a last element. They
may be the same element.
>Finding the first is easy, but grabbing the last only if there are multiple
>elements seems to require something like:
>?(arraysize("abcd",".") > 1,array("abcd",arraysize("abcd","."),"."),"")
>
>The appeal of arraylast( is being to reliably get the last element
>without having to calculate where it is or if it even exists.
The last element always exist. When you look at the array from the
front, the 1st element is the 1st element. When you look at an array
from the rear, the 1st element is the last element. They may be the
same element but when you are considering the 1st element or the last
element, the issue of whether there are any other elements in the
series is a non issue.
--
<><><><><><><><><><><><><><><><><><>
Robert Ameeti
mailto:robert at ameeti.net
<><><><><><><><><><><><><><><><><><>
More information about the Qna
mailing list