Association list utilities Lassi Kortela (10 Jun 2020 08:24 UTC)
Re: Association list utilities Marc Nieper-Wißkirchen (10 Jun 2020 08:30 UTC)
Re: Association list utilities Lassi Kortela (10 Jun 2020 08:49 UTC)
Re: Association list utilities Marc Nieper-Wißkirchen (10 Jun 2020 09:29 UTC)
Re: Association list utilities Lassi Kortela (10 Jun 2020 09:59 UTC)
Re: Association list utilities Marc Nieper-Wißkirchen (10 Jun 2020 10:09 UTC)
Re: Association list utilities Lassi Kortela (10 Jun 2020 10:37 UTC)
Re: Association list utilities Arne Babenhauserheide (10 Jun 2020 10:33 UTC)

Re: Association list utilities Lassi Kortela 10 Jun 2020 10:37 UTC

>     You can also store a list as the value of each hash-table entry,
>
>     Hence I'd suggest starting from the fact that any key->value collection
>     (John would call them dictionaries) can have lists for values.
>
> Values are usually not restricted. There's just the question of how to
> interpret the value. A list can either mean a single object, which
> happens to be a list, or multiple values, where it has been an
> implementation choice to store them as a list.

Since Scheme is dynamically typed, an alist is an alist by construction
anyway. There is no way to restrict it from becoming something else.

If we stay with the classic definition of alists -- that they are (key .
value) pairs where the cdr is the value -- then we have something that's
symmetrical with hash-tables, mappings and other dictionaries.

Convenience procedures that treat the value as a list are very useful,
no matter what the underlying container is. For example, "append to
hash-table key" is really great to be able to do in one operation:

(define (hash-table-push! hash-table key new-element)
   (hash-table-update!/default
    hash-table
    key
    (lambda (old-elements) (append old-elements (list new-element)))
    '()))

(define tab (make-hash-table (make-equal-comparator)))
(hash-table-push! tab "a" 1)  ; => (1)
(hash-table-push! tab "a" 2)  ; => (1 2)
(hash-table-push! tab "a" 3)  ; => (1 2 3)