On Apr 5, 10:08 pm, jon <superuser...@googlemail.com
> So is there scope for a new standard library function for this
> intuitive usage?
> (don't know what to call it, because to my mind 'nth' is the ideal
> name and the current 'nth' is more like an 'idx' (or 'ith') as is
> tries to look up values by their "index").
It always bothered me in Common Lisp that
(nth 1 list) == (second list)
but I guess it's traditional.
You could define something like this:
"Returns the 'nth' (one-based) item in the
sequence, nil if it does not exist. 'ord'
is short for 'ordinal'."
(first (nthrest coll (dec n))))
user=> (def xs [1 2 3])
user=> (ord 1 xs)
user=> (ord 2 xs)
user=> (ord 3 xs)
user=> (ord 4 xs)
user=> (ord 0 xs) ; nonsensical but works for now
I also noticed that this doesn't raise an exception:
user=> (nth nil 2)