From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Lam Newsgroups: gmane.lisp.guile.user Subject: Re: Simple list of key-value pairs? Date: Thu, 8 Jul 2021 15:22:29 +0000 Message-ID: References: <410e7168-3709-c961-c894-d534782ef526@crazy-compilers.com> 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="6093"; 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 Thu Jul 08 17:53:10 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 1m1WKs-0001SS-Gn for guile-user@m.gmane-mx.org; Thu, 08 Jul 2021 17:53:10 +0200 Original-Received: from localhost ([::1]:45854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1WKr-0005YG-Fg for guile-user@m.gmane-mx.org; Thu, 08 Jul 2021 11:53:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55396) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Vrq-00048t-Qx for guile-user@gnu.org; Thu, 08 Jul 2021 11:23:11 -0400 Original-Received: from mail-qv1-xf33.google.com ([2607:f8b0:4864:20::f33]:41844) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m1Vrf-0001FY-1k for guile-user@gnu.org; Thu, 08 Jul 2021 11:23:09 -0400 Original-Received: by mail-qv1-xf33.google.com with SMTP id f5so2969723qvu.8 for ; Thu, 08 Jul 2021 08:22:56 -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=3dh43QiM9TGEQCPGpvgj1DK+tOB0F9QPPFhs+ircoVY=; b=ZTA/M2E8aUYOU6WZX3e+rD8jXaT62Tf6PF0YABPisz7AYoMmCS7+bBWL1bO3J5iT1Q bUVaHeVs4k1K4uUjtTqLbeotua89cbRXjQAM5vWcUf+w44nvGvSN+2mPNFvs6J5iK0It 0FSI+fkCtw0TH0WxWEt8MsewW7bT23zIWorVueReXFU2qgPrJ99ert1QVacbxqRSU9/y uWiUH8IZ1d62mcWiuIEEoFHMQSc7WVcRKQCnd79dfe3y4rRFfqZNSmySSeovrL0VidY+ S8KSW5G2jwlfNpaB2tDN/4hg9nqtBJPxAGBSk0aHGMfaOK96rJL38m9fKjOt6Vp0PXBa d/gg== 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=3dh43QiM9TGEQCPGpvgj1DK+tOB0F9QPPFhs+ircoVY=; b=XeF0NpiKN++dSvwJ75R8T/YN2e7QKYCt4FebwbIGbsQPiyQKgQn91hFe/nTp/qTmlu 2tBZNokLKOl9+ugpmiI/dcU7dXwb69cHtPuUedMqjNEoM7nIKYbU9n9/dRZzjgkZBPPM Phae0JewHKfsoF/+WsaKZ9do6VsFiKF2FoJO6yfsSB3DPRfJ3GlbDt2w2+jQH8YCyAZS 5x4yUIDyA0AMV9gBFHV7oXXQ05uibhmKQytRoOLXYvr0tFp8AySh/R4uDSiYcnHLUBha WjhibG/YmgoQaXGA7nGu6r/CgQazOE3fnKwnyy13E9pZugZQMyp7nRqwmrGkXCVYWHds vNKA== X-Gm-Message-State: AOAM533I+T7+ZPc1nx0acDM1IcS62SXKUkpFTcf/nkldgkTkS39FD7YH 9/5/MYFrlsaaJSLZMWUk2sgkSZCrEGE2HJso2fcPeq3OjGrulw== X-Google-Smtp-Source: ABdhPJwfQPpwIESqNffJomuHnnNKXpsYg6Usj6cFEUSElOpVx/iEBf4ifR2+YVvst3PN1xjf85mmrsNbpB4xtkUPqHg= X-Received: by 2002:a0c:fe42:: with SMTP id u2mr30346407qvs.27.1625757776046; Thu, 08 Jul 2021 08:22:56 -0700 (PDT) In-Reply-To: <410e7168-3709-c961-c894-d534782ef526@crazy-compilers.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::f33; envelope-from=christopher.lck@gmail.com; helo=mail-qv1-xf33.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:17643 Archived-At: IMO quotes and quasiquotes are being used perfectly well. You can use '(system #f). However I suspect building a list of intermediate strings is not desirable. And we may want to eliminate map and filter. How about building the query-string piecemeal then building the final string once? (define (build-query-string) (let lp ((query (or query '())) (acc '())) (match query (() (string-concatenate acc)) (((_ #f) . rest) (lp rest acc)) (((name val) . rest) (lp rest (cons* name "=" (if (string? val) val (object->string val)) (if (null? acc) "" "&") acc)))))) On Thu, 8 Jul 2021 at 14:37, 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)) > > -- > Regards > Hartmut Goebel > > | Hartmut Goebel | h.goebel@crazy-compilers.com | > | www.crazy-compilers.com | compilers which you thought are impossible | > > >