From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Wingo Subject: Re: [PATCH 3/3] gnu: Add CUPS service. Date: Mon, 10 Oct 2016 10:55:51 +0200 Message-ID: References: <20161007202424.26732-1-wingo@igalia.com> <20161007202424.26732-3-wingo@igalia.com> <874m4ktxi5.fsf@lassieur.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]:47535) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWNS-0005Qd-Mg for guix-devel@gnu.org; Mon, 10 Oct 2016 04:56:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btWNP-00023p-GM for guix-devel@gnu.org; Mon, 10 Oct 2016 04:56:06 -0400 Received: from pb-sasl1.pobox.com ([64.147.108.66]:50947 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWNP-0001yo-9H for guix-devel@gnu.org; Mon, 10 Oct 2016 04:56:03 -0400 In-Reply-To: <874m4ktxi5.fsf@lassieur.org> (=?utf-8?Q?=22Cl=C3=A9ment?= Lassieur"'s message of "Mon, 10 Oct 2016 10:32:34 +0200") 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: =?utf-8?Q?Cl=C3=A9ment?= Lassieur Cc: guix-devel@gnu.org On Mon 10 Oct 2016 10:32, Cl=C3=A9ment Lassieur writ= es: >> +(define-record-type* >> + configuration-field make-configuration-field configuration-field? >> + (name configuration-field-name) >> + (type configuration-field-type) >> + (getter configuration-field-getter) >> + (predicate configuration-field-predicate) >> + (serializer configuration-field-serializer) >> + (default-value-thunk configuration-field-default-value-thunk) >> + (documentation configuration-field-documentation)) >> + >> +(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))))= )))) >> + (syntax-case stx () >> + ((_ stem (field (field-type def) doc) ...) >> + (with-syntax (((field-getter ...) >> + (map (lambda (field) >> + (id #'stem #'stem #'- field)) >> + #'(field ...))) >> + ((field-predicate ...) >> + (map (lambda (type) >> + (id #'stem type #'?)) >> + #'(field-type ...))) >> + ((field-serializer ...) >> + (map (lambda (type) >> + (id #'stem #'serialize- type)) >> + #'(field-type ...)))) >> + #`(begin >> + (define-record-type* #,(id #'stem #'< #'stem #'>) >> + stem #,(id #'stem #'make- #'stem) #,(id #'stem #'stem = #'?) >> + (field field-getter (default def)) >> + ...) >> + (define #,(id #'stem #'stem #'-fields) >> + (list (configuration-field >> + (name 'field) >> + (type 'field-type) >> + (getter field-getter) >> + (predicate field-predicate) >> + (serializer field-serializer) >> + (default-value-thunk (lambda () def)) >> + (documentation doc)) >> + ...)))))))) >> + >> +(define (serialize-configuration config fields) >> + (for-each (lambda (field) >> + ((configuration-field-serializer field) >> + (configuration-field-name field) >> + ((configuration-field-getter field) config))) >> + fields)) >> + >> +(define (validate-configuration config fields) >> + (for-each (lambda (field) >> + (let ((val ((configuration-field-getter field) config))) >> + (unless ((configuration-field-predicate field) val) >> + (cups-configuration-field-error >> + (configuration-field-name field) val)))) >> + fields)) > > These definitions are also in the Dovecot service. Would it make sense > to put them in a place where they could be accessible from other > services as well, thus avoiding code repetition? Yes, it's a good idea. I was holding off doing it until the third service that used them, though, just to avoid prematurely making an abstraction that might be the wrong thing; dunno. WDYT? Andy