|Subject:||Re: [Chicken-users] Alist versus Hash-table|
|Date:||Wed, 13 Nov 2013 02:44:04 +0400|
As Peter said, the Query String format doesn’t prevent you from using multiple time the same key for multiple values. One concrete example would be a form with a couple of checkboxes. A group of checkbox could be named “ingredients”. Each checkbox could have different values. Like Onions, Ananas, Pepperoni… When you select multiple ingredients you should have something like this:
Which should be converted to a alist like this:
((ingredient . ananas) (ingredient . onions) (ingredient . cheese))
As far as I can tell, in python this kind of structure is implemented as a MultiDict. It’s a hash-table that allows multiple values (in a list) for a key. The Query string is one of the rare cases where the alist makes more sense but a multi-dict could be implemented easily using the hash-table.
(define (multi-hash-ref htable key)
(let ((val (hash-table-ref htable key)))
(if (or (eq? val #f) (null? val))
(define (multi-hash-ref-all htable key)
(hash-table-ref htable key))
Here, we assume that each value for a key is supposed to be a list. The list can be empty.
Sent with Airmail
On November 13, 2013 at 1:39:52 AM, Peter Bex (address@hidden) wrote:
|[Prev in Thread]||Current Thread||[Next in Thread]|