From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH 2/2] utils: Support defaults in substitute-keyword-arguments. Date: Sat, 24 Sep 2016 11:21:40 +0900 Message-ID: <87mviyf363.fsf@gnu.org> References: <20160920212916.18530-1-ericbavier@openmailbox.org> <20160920212916.18530-2-ericbavier@openmailbox.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39087) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bncko-0003c2-RA for guix-devel@gnu.org; Fri, 23 Sep 2016 22:31:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnckm-0002tM-UK for guix-devel@gnu.org; Fri, 23 Sep 2016 22:31:49 -0400 In-Reply-To: <20160920212916.18530-2-ericbavier@openmailbox.org> (Eric Bavier's message of "Tue, 20 Sep 2016 16:29:16 -0500") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Eric Bavier Cc: guix-devel@gnu.org, Eric Bavier Eric Bavier skribis: > From: Eric Bavier > > * guix/utils.scm (substitute-keyword-arguments): Allow default value > declarations. > * tests/utils.scm (substitute-keyword-arguments): New test. Good idea! [...] > +replaced by EXP. EXP is evaluated in a context where VAR is bound to the > +previous value of the keyword argument, or DFLT if given." > + (syntax-case x () > + ((_ original-args ((kw var dflt ...) exp) ...) > + #`(let loop ((args (default-keyword-arguments > + original-args > + (list #,@(append-map (match-lambda > + ((k) '()) > + (x x)) > + #'((kw dflt ...) ...)))= )) > + (before '())) I would prefer to stick to =E2=80=98syntax-rules=E2=80=99 when matching the= clauses, with a helper macro: (define-syntax expand-default-args (syntax-rules () ((_ original args ((kw var) expr) rest ...) ...) ((_ original args ((kw var default) expr) rest ...) ...))) =E2=80=A6 (syntax-rules () ((_ original-args ((clause exp) ...) (let loop ((args (expand-default-args original-args clause ...))) =E2=80=A6)))) But this would be a bonus; the patch LGTM. Thanks! Ludo=E2=80=99.