From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH 3/3] gnu: Add CUPS service. Date: Mon, 10 Oct 2016 23:00:35 +0200 Message-ID: <87shs3gbrg.fsf@gnu.org> 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]:42877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bthgn-0001pb-Gw for guix-devel@gnu.org; Mon, 10 Oct 2016 17:00:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bthgi-0006ac-MB for guix-devel@gnu.org; Mon, 10 Oct 2016 17:00:49 -0400 In-Reply-To: (Andy Wingo's message of "Mon, 10 Oct 2016 10:55:51 +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: Andy Wingo Cc: guix-devel@gnu.org, =?utf-8?Q?Cl=C3=A9ment?= Lassieur Andy Wingo skribis: > On Mon 10 Oct 2016 10:32, Cl=C3=A9ment Lassieur wr= ites: > >>> +(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? I think Cl=C3=A9ment has a point. ;-) Maybe in a subsequent patch it could be moved as-is to (gnu services configuration) or something along these lines? Thanks, Ludo=E2=80=99.