;'<<SPEC'
<!--
Copyright (c) 2012-2024, Chris Pressey, Cat's Eye Technologies.
This file is distributed under a 2-clause BSD license. See LICENSES/ dir.
SPDX-License-Identifier: LicenseRef-BSD-2-Clause-X-Robin
-->
### `last` ###
-> Tests for functionality "Evaluate Robin Expression (with List)"
`last` evaluates its first argument to obtain a non-negative integer,
considered to be a desired length, and its second argument to obtain a
list. It then evaluates to the suffix of the given list of the desired
length.
| (last 0 (list 1 2 3 4 5))
= ()
| (head (last 1 (list 1 2 3 4 5)))
= 5
| (last 3 (list 1 2 3 4 5))
= (3 4 5)
| (last 6 (list 1 2 3 4 5))
? abort (expected-list ())
| (last 1 (literal foo))
? abort (expected-list foo)
Unlike `first`, `last` does care if it's not a list, even when the count
is zero.
| (last 0 (literal foo)))
? abort (expected-list foo)
'<<SPEC'
(define last (fun (n li)
(reverse (first n (reverse li)))))