To make a long story short I was using a variable to get the last n items of a list and noticed something that feels wrong to me. The calculation that sets the variable will often set the variable to zero. For other values of n last<n>
will return the last n items in the list but if n=0 the entire list is returned when it would make more sense to return nothing (which is what I would like it to do). Some trivial test wiki text-
\define theNum() 3
\define zero() 0
\define theList() A B C D E F G H I J
Last:
2: {{{ [enlist<theList>last[2]] }}}
nothing: {{{ [enlist<theList>last[]] }}}
<<theNum>>: {{{ [enlist<theList>last<theNum>] }}}
<<zero>>: {{{ [enlist<theList>last<zero>] }}}
First:
2: {{{ [enlist<theList>first[2]] }}}
nothing: {{{ [enlist<theList>first[]] }}}
<<theNum>>: {{{ [enlist<theList>first<theNum>] }}}
<<zero>>: {{{ [enlist<theList>first<zero>] }}}
gives these results:
Last:
2: IJ
nothing: J
3: HIJ
0: ABCDEFGHIJ
First:
2: AB
nothing: A
3: ABC
0:
So first[] behaves in the way I’d expect, you calculate that you need a certain number of items from the beginning of the list and if that number turns out to be zero, you get no items, but last[] gives you the whole list under the same circumstances.
I’ve “solved” my problem by coding a special case using a compare operator but because of the calculation and a bunch of other manipulation of the list, it’s a bit of a mess, so I don’t need a solution but I am wondering if there is something I’m missing.
Is there an easy way to get the last n items from a list when n can be zero?
Does the behavior of last[0], especially when compared to first[0] feel like a problem?