[plt-scheme] Re: net collection: bindings -> post-bytes?
>
> (define (bindings->post-bytes l)
> (define (string->post-bytes s)
> (string->bytes/utf-8 (form-urlencoded-encode s)))
> (define symbol->post-bytes
> (compose string->post-bytes symbol->string))
> (define (one-arg sym val)
> (bytes-append (symbol->post-bytes sym) #"=" (string->post-bytes
> val)))
> ;; -- IN --
> (bytes-join (map (curry apply one-arg) l) #"&"))
>
> (provide/contract
> [bindings->post-bytes
> (-> (listof (list/c symbol? string?)) bytes?)])
I wanted to rewrite your module as the above 'one-liner' plus contract,
but then I realized that we don't have an analogue for string/13 for
bytes.
(That is, I had to write
> (define (bytes-join lob sep)
> (define l (reverse lob))
> (foldl (lambda (f r) (bytes-append f sep r)) (first l) (rest l)))
)
Any volunteers?