From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?Cl=C3=A9ment?= Lassieur Subject: Re: [PATCH 2/5] services: Factorize define-maybe macro. Date: Thu, 16 Mar 2017 18:25:47 +0100 Message-ID: <874lytjfqc.fsf@lassieur.org> References: <20170315204642.27626-1-m.othacehe@gmail.com> <20170315204642.27626-3-m.othacehe@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coZ9u-0001su-Mw for guix-devel@gnu.org; Thu, 16 Mar 2017 13:25:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coZ9r-0001he-Ab for guix-devel@gnu.org; Thu, 16 Mar 2017 13:25:54 -0400 Received: from mail.lassieur.org ([83.152.10.219]:35972) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coZ9r-0001gM-0b for guix-devel@gnu.org; Thu, 16 Mar 2017 13:25:51 -0400 In-reply-to: <20170315204642.27626-3-m.othacehe@gmail.com> 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: Mathieu Othacehe Cc: guix-devel@gnu.org Mathieu Othacehe writes: > * gnu/services/configuration.scm (define-maybe): New exported > procedure. > (id): New procedure extracted from define-configuration. > * gnu/services/messaging.scm (define-all-configurations): Define id > inside procedure as define-all-configurations is now the only user. > --- > gnu/services/configuration.scm | 28 ++++++++++++++++++++-------- > gnu/services/messaging.scm | 22 +++------------------- > 2 files changed, 23 insertions(+), 27 deletions(-) > > diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm > index 2ad3a637a..3fdaf705a 100644 > --- a/gnu/services/configuration.scm > +++ b/gnu/services/configuration.scm > @@ -1,5 +1,6 @@ > ;;; GNU Guix --- Functional package management for GNU > ;;; Copyright © 2015 Andy Wingo > +;;; Copyright © 2017 Mathieu Othacehe > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -36,6 +37,7 @@ > configuration-field-default-value-thunk > configuration-field-documentation > serialize-configuration > + define-maybe > define-configuration > validate-configuration > generate-documentation > @@ -85,16 +87,26 @@ > (configuration-field-name field) val)))) > fields)) > > +(define-syntax-rule (id ctx parts ...) > + (datum->syntax ctx (symbol-append (syntax->datum parts) ...))) The docstring was helpful! Could you put it too? > +(define-syntax define-maybe > + (lambda (x) > + (syntax-case x () > + ((_ stem) > + (with-syntax > + ((stem? (id #'stem #'stem #'?)) > + (maybe-stem? (id #'stem #'maybe- #'stem #'?)) > + (serialize-stem (id #'stem #'serialize- #'stem)) > + (serialize-maybe-stem (id #'stem #'serialize-maybe- #'stem))) > + #'(begin > + (define (maybe-stem? val) > + (or (eq? val 'disabled) (stem? val))) > + (define (serialize-maybe-stem field-name val) > + (when (stem? val) (serialize-stem field-name val))))))))) > + > (define-syntax define-configuration > (lambda (stx) > - (define (id ctx part . parts) > - (let ((part (syntax->datum part))) > - (datum->syntax > - ctx > - (match parts > - (() part) > - (parts (symbol-append part > - (syntax->datum (apply id ctx parts)))))))) I think this part, that replaces the old version of "id" with the new one deserves a specific patch, because it is not directly related to moving define-maybe, and because it does more that just "moving code". > (syntax-case stx () > ((_ stem (field (field-type def) doc) ...) > (with-syntax (((field-getter ...) > diff --git a/gnu/services/messaging.scm b/gnu/services/messaging.scm > index 34723dc11..e50eeba8c 100644 > --- a/gnu/services/messaging.scm > +++ b/gnu/services/messaging.scm > @@ -1,5 +1,6 @@ > ;;; GNU Guix --- Functional package management for GNU > ;;; Copyright © 2017 Clément Lassieur > +;;; Copyright © 2017 Mathieu Othacehe > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -49,27 +50,10 @@ > ;;; > ;;; Code: > > -(define-syntax-rule (id ctx parts ...) > - "Assemble PARTS into a raw (unhygienic) identifier." > - (datum->syntax ctx (symbol-append (syntax->datum parts) ...))) > - > -(define-syntax define-maybe > - (lambda (x) > - (syntax-case x () > - ((_ stem) > - (with-syntax > - ((stem? (id #'stem #'stem #'?)) > - (maybe-stem? (id #'stem #'maybe- #'stem #'?)) > - (serialize-stem (id #'stem #'serialize- #'stem)) > - (serialize-maybe-stem (id #'stem #'serialize-maybe- #'stem))) > - #'(begin > - (define (maybe-stem? val) > - (or (eq? val 'disabled) (stem? val))) > - (define (serialize-maybe-stem field-name val) > - (when (stem? val) (serialize-stem field-name val))))))))) > - > (define-syntax define-all-configurations > (lambda (stx) > + (define-syntax-rule (id ctx parts ...) > + (datum->syntax ctx (symbol-append (syntax->datum parts) ...))) This could go in the second patch as well. > (define (make-pred arg) > (lambda (field target) > (and (memq (syntax->datum target) `(common ,arg)) field)))