From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Aleix_Conchillo_Flaqu=C3=A9?= Newsgroups: gmane.lisp.guile.user Subject: Re: Simple list of key-value pairs? Date: Fri, 9 Jul 2021 15:37:49 -0700 Message-ID: References: <410e7168-3709-c961-c894-d534782ef526@crazy-compilers.com> <52395f5c-a470-1b47-2c5a-7274bbd14940@posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38873"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Zelphir Kaltstahl Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Jul 10 00:38:20 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1z8W-0009sv-3U for guile-user@m.gmane-mx.org; Sat, 10 Jul 2021 00:38:20 +0200 Original-Received: from localhost ([::1]:56586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1z8T-0001pq-SN for guile-user@m.gmane-mx.org; Fri, 09 Jul 2021 18:38:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1z8H-0001pT-GF for guile-user@gnu.org; Fri, 09 Jul 2021 18:38:05 -0400 Original-Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:34403) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m1z8F-00006m-8h for guile-user@gnu.org; Fri, 09 Jul 2021 18:38:05 -0400 Original-Received: by mail-pj1-x102f.google.com with SMTP id g6-20020a17090adac6b029015d1a9a6f1aso7860475pjx.1 for ; Fri, 09 Jul 2021 15:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2Uwa4RK+QFL5cHFE+d/RFxAdXYL5mjguBMPTYrWwFjA=; b=h0eUVvxagF3NynFTKlhwzNUa31n+5GO7MFJclmDaZDsMegpBMDGXBgR08DRDiIS/Xf PRbbLE2/mb6jR2A0WMuz82xp9qTWaorgWBY3OinfZ1JSOJ2fUUBMpj4VFqfOsh/pTNsL ybcTsDIMB0DZ3E3AKpMZxwpOJMGA6di5IsqHh6OkpUe7vuhMdUn44DQgd1XcDyAZOEKa bog43gWFn76l0LqlmrU6Tf7hFMLjMfogxTRM+h41kU1B2CWtTSpCBLu/ME3cRtlPfEIy F0lcUnowQ/+PKGh+lh4kxn/sx+JNqVXXlX9dsA1CWDkx1aZBdtAjOafuzljxsIdSPEMi yCZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2Uwa4RK+QFL5cHFE+d/RFxAdXYL5mjguBMPTYrWwFjA=; b=l2azrjzTKkWxjRcLKyO49yJOmyZX6H7f5nu6P8TzAsnCQcrSFVYfm/Qm4DImk3DHwq 4hd6LPsgpb5Nk2OdAfq2ClmgUBhcav06svf0PSmi5SkhRqPgzrcxnSkvyaL3AwDq22pQ aQ8i8JKpKN9ImtjKyJKNTMJKWC260lsVTcCTImzVkhmkMYOf+OAgpF5Cf7WdzI8s7qnf O6eNep0O4nvWyKsy9vQTfSGHiFBS/jnVZ/7++TCpilBzHQDfzaFHkSq7ydGpI+sIS84l vqbOKtXdx8pJRXJOMUpjKhe7WDOlO3XQN8SUxZIprQJ6UYRvjeQZ7d3mTum2Vidz8Uqv yNeA== X-Gm-Message-State: AOAM530JOtC/L/teBMNvdZdL/emHmfhv7qhaxZ1MuBYmt9siPNvuhlK2 Pdd8U7y4zLSnIAve2ZVVLuIETC/bHmxmEqCpL28= X-Google-Smtp-Source: ABdhPJyLyQa2/yr4ZY6CdT2z/o4uyya+PsldHE+j18Zr33GH/uAG6ckQd+V6IqR0faNy65YCSWpKGQV3Dm8OiuOmxSM= X-Received: by 2002:a17:902:830b:b029:12a:dd1b:74bf with SMTP id bd11-20020a170902830bb029012add1b74bfmr4794107plb.44.1625870280820; Fri, 09 Jul 2021 15:38:00 -0700 (PDT) In-Reply-To: <52395f5c-a470-1b47-2c5a-7274bbd14940@posteo.de> Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=aconchillo@gmail.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17647 Archived-At: Hello, I would also use Zelphir's approach and pass query parameters as an alist, the reason is because then you can dynamically generate that alist more easily if needed and even pass it around, and it looks nicer to me but that's a personal choice. I would also actually make that an optional argument instead and explicitly pass it with #:query-params. (api-uri "https://ci.guix.gnu.org" "/api/jobs" #:query-params `(("nr" . ,limit) ("evaluation" . ,evaluation) ("system" . #f))) Aleix On Fri, Jul 9, 2021 at 4:37 AM Zelphir Kaltstahl wrote: > Hi! > > I think I would give the pairs together in an association list and use > alist > procedures to work with that. Then you could also only have one backtick, > at the > start of the alist: > > ~~~~ > `((attr . ,val) > (attr . ,val) > (attr . ,val) > (attr . ,val)) > ~~~~ > > Looks simpler to me and fewer special characters. > > Regards, > Zelphir > > On 7/8/21 4:37 PM, Hartmut Goebel wrote: > > 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)) > > > -- > repositories: https://notabug.org/ZelphirKaltstahl > >