On 07/04/2016 10:39 AM, oldk1331 wrote:
> It's defined in UnaryRecursiveAggregate of aggcat.spad:
>    last : (%, NonNegativeInteger) -> %
>       ++ last(u, n) returns a copy of the last n (\spad{n >= 0}) nodes of u.
>       ++ Note: \spad{last(u, n)} is a list of n elements.
> 
> 
> However, I think this signature is more suitable for tail,
> after all, we already have:
> 
> last : D -> D1 from D if D has URAGG(D1) and D1 has TYPE
> tail : D -> D from D if D has URAGG(D1) and D1 has TYPE
> 
> 
> So the reasonable extension is last(a,n) returns the nth last
> element and tail(a,n) returns the list of last n elements.

I would simply rename the signature to

  tail: (%, NonNegativeInteger) -> %

With your suggestion of last: (SomeAggregate X, NNI) -> X, then
with last([1,2,3,4,5,6],2) would I expect 5 or 4?

Maybe we can also introduce negative indices in elt, so that
elt([1,2,3,4,5], -2) gives 4. Hmmm, but maybe, that's a bad suggestion
since minIndex could be -2, then elt([1,2,3,4,5], -2) should (of course)
give the first element 1.

Ooops... I just looked into UnaryRecursiveAggregate. Such a structure
can have loops. What would be the last element of a looped list that is
[1,2,1,2,1,2,1,2,1,2,...].
The docstring says:

last: % -> S
    last(u) resturn the last element of u. Note: for lists,
    last(u) = u . (maxIndex u) = u . (\# u - 1).

But there is no "maxIndex" defined for UnaryRecursiveAggregate.

Ralf

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to