From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Re: Simple list of key-value pairs? Date: Fri, 9 Jul 2021 11:31:01 +0000 Message-ID: <52395f5c-a470-1b47-2c5a-7274bbd14940@posteo.de> References: <410e7168-3709-c961-c894-d534782ef526@crazy-compilers.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27639"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Hartmut Goebel Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Jul 09 13:37:22 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 1m1oos-00071g-JM for guile-user@m.gmane-mx.org; Fri, 09 Jul 2021 13:37:22 +0200 Original-Received: from localhost ([::1]:38526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1oor-0000Dw-Kv for guile-user@m.gmane-mx.org; Fri, 09 Jul 2021 07:37:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1oit-0003Th-Bc for guile-user@gnu.org; Fri, 09 Jul 2021 07:31:11 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:40679) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1oiq-0001oS-6h for guile-user@gnu.org; Fri, 09 Jul 2021 07:31:11 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 4E0BB240029 for ; Fri, 9 Jul 2021 13:31:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1625830263; bh=R29GNHdRCqUsm8oCKb3UXI3o+FWx7W+tlU7XWA+FR7U=; h=Subject:To:Cc:From:Date:From; b=Gy3dJ9lNKF1P2mLC5kCCuwjdlV8O16Qz3uainQMbJ8/RPmdLorsUrF+XkK28aZi7u A4AEr2nWeGpxCnhsE2rnGe55O+kefST2AoUN/EFWMU03RsrsuP5Eee8DiWt08SxNrl 27yXAkaVH0r/7qWy4svMznNDCmdIc3KLNMH/qpENLmqbW/oLx2/sNHnvdo8JLpTchk 3J0VBlyQfAuiNdR5JgEq2xGDmPOB1Aj+lH8fC1WOodEaG1ju0MZBrLUU5RhmhYEq5L T/4lW+sUr6p6/qAPjsuXpZnj7XYtxtfEvyUJQiiN6pCSuUXL+VzKFii1KPapZrLSJr 7vxXbEVbuybWQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4GLrZZ4m07z9rxn; Fri, 9 Jul 2021 13:31:02 +0200 (CEST) In-Reply-To: <410e7168-3709-c961-c894-d534782ef526@crazy-compilers.com> Content-Language: en-US Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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:17645 Archived-At: 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