unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Simple list of key-value pairs?
@ 2021-07-08 14:37 Hartmut Goebel
  2021-07-08 15:22 ` Christopher Lam
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Hartmut Goebel @ 2021-07-08 14:37 UTC (permalink / raw)
  To: guile-user

Hi,

I'm seeking advice for passing simple key-value pairs to a function and 
generate a string out of these values. Neither the names not the number 
of keys is known in advance.

Background: This shall become a generic function for generating URI 
query-strings.

My current approach please see below. Anyhow, I'm wondering whether the 
quite and quasiquote can be replaced by something simpler.

(use-modules (ice-9 match))

(define limit 100)
(define evaluation "linux")

(define* (api-uri base path #:rest query)

   (define (build-query-string kv)
     (match kv
        ((name #f) #f)
        ((name (? string? value))
         (string-append name "=" value))  ; FIXME: encode
        ((name (? number? value))
         (string-append name "=" (number->string value)))))


   (format #t "~%Query: ~a~%~%" query)
   (let ((query-string
      (when query
        (string-join
         (filter (lambda (x) x) (map build-query-string query))
         "&"))))
     (format #t "~%Query-String: ~a~%~%" query-string)
     ;; todo: build uri incl. query-string
   ))


(api-uri "https://ci.guix.gnu.org" "/api/jobs")
(api-uri "https://ci.guix.gnu.org" "/api/jobs"
      `("nr" ,limit)
      `("evaluation" ,evaluation)
      `("system" ,#f))

-- 
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goebel@crazy-compilers.com               |
| www.crazy-compilers.com | compilers which you thought are impossible |




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-07-09 22:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 14:37 Simple list of key-value pairs? Hartmut Goebel
2021-07-08 15:22 ` Christopher Lam
2021-07-08 18:59 ` Luis Felipe
2021-07-09 11:31 ` Zelphir Kaltstahl
2021-07-09 22:37   ` Aleix Conchillo Flaqué
2021-07-09 11:55 ` Tim Van den Langenbergh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).