My design as it now stands is agnostic to the kind of dictionary used.  In your design, though, how do you get the oldest/youngest key?  I'm not sure I understand it.

I really need to get <https://bitbucket.org/cowan/r7rs-wg1-infra/src/default/Dictionaries.md> implemented.  It's easy, but there's a lot of fiddly bits of code.

On Thu, Mar 12, 2020 at 5:51 PM Arthur A. Gleckler <xxxxxx@speechcode.com> wrote:
On Thu, Mar 12, 2020 at 8:31 AM John Cowan <xxxxxx@ccil.org> wrote:
 
My reply to this turned into a pre-pre-SRFI, so please read it at <https://bitbucket.org/cowan/r7rs-wg1-infra/src/default/SortedDictionaries.md>.

Comments and corrections?

I like the idea of being able to use alists rather than inventing a new data structure for bidirectional lists.

Still, I wonder about using HAMTs (Hash Array Mapped Tries) as the basis instead.  Thinking about this a bit more, if one kept a HAMT mapping keys to pairs of keys or #f, then the car of each pair could represent the element to the left in the list, if any, and the cdr could represent the element to the right, if any.  (If one wanted to be able to store #f as a key, one could use a special value to represent that there was no adjacent key in that direction.)  HAMTs can be persistent, and the implementation that I contributed for SRFI 146 follows Clojure's model by allowing one to switch between persistent and mutable states.  (The mutable version reduces constant-time overhead.)  This design would allow for quick deletion and insertion in the middle of the list, too.

It has been a long time since I thought about HAMTs, but this seems doable and practical.

This reminds me that I need to read Okasaki's Purely Functional Data Structures book.  It's on my shelf, and the reviews say it's fantastic, but I haven't gotten around to it.