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:

?ingredient=ananas&ingredient=onions&ingredient=cheese

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))
         #f
         (car 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.



-- 
Loïc Faure-Lacroix
Sent with Airmail

On November 13, 2013 at 1:39:52 AM, Peter Bex ([email protected]) wrote:

On Tue, Nov 12, 2013 at 04:34:51PM -0500, John Cowan wrote:  
> > Also, in some cases duplicate entries really mean something different  
> > (for example in alist->uri query attribute mappings and such).  
>  
> I don't understand this example.  

((a . "foo") (a . "bar")) => ?a=foo;a=bar  

A HTTP server might interpret this query string differently from ?a=foo  

Cheers,  
Peter  
--  
http://www.more-magic.net  
_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to