# Re: (rank)

```Hi Lindsay,

> My sample code ("ABRA..) is wrong. Sorry about that.```
```
Ah, I see. No problem.

> : (rank 'c '((a . a) (b . b) (d . d)) T)   # ???
> -> NIL
> : (rank 'd '((a . a) (b . b) (d . d)) T)   # ???
> -> NIL
>
> : (rank 'd '((a . a) (b . b) (d . d)))
> -> (d . d)
> : (rank 'c '((a . a) (b . b) (d . d)))
> -> (b . b)
>
> The latter two work as I would expect.
> I expected the first two to return '(d . d)....

The reason here is that 'rank' expects a *sorted* list. It traverses the list,
and stops as soon as it can confirm or refute the desired condition.

With a second argument non-NIL, it tries to "Returns the element from lst ...
with a minimal CAR greater or equal to any". However, already the first element
(a . a) is *less* than 'c' or 'd', hence it returns NIL.

If you reverse the list, it works:

: (rank 'c '((d . d) (b . b) (a . a)) T)
-> (d . d)

: (rank 'b '((d . d) (b . b) (a . a)) T)
-> (b . b)

It is the purpose of the second argument to tell 'rank' in which direction it
should expect the list to be sorted.

♪♫ Alex

--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
```