From: ludo@gnu.org (Ludovic Courtès)
To: Andy Wingo <wingo@igalia.com>
Cc: guix-devel@gnu.org, "Clément Lassieur" <clement@lassieur.org>
Subject: Re: [PATCH 3/3] gnu: Add CUPS service.
Date: Mon, 10 Oct 2016 23:00:35 +0200 [thread overview]
Message-ID: <87shs3gbrg.fsf@gnu.org> (raw)
In-Reply-To: <cuch98ktwfc.fsf@igalia.com> (Andy Wingo's message of "Mon, 10 Oct 2016 10:55:51 +0200")
Andy Wingo <wingo@igalia.com> skribis:
> On Mon 10 Oct 2016 10:32, Clément Lassieur <clement@lassieur.org> writes:
>
>>> +(define-record-type* <configuration-field>
>>> + 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ément 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’.
next prev parent reply other threads:[~2016-10-10 21:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-07 20:24 [PATCH 1/3] gnu: cups-filters: Look for test page in own output dir Andy Wingo
2016-10-07 20:24 ` [PATCH 2/3] gnu: cups-filters: Use ghostscript with CUPS driver Andy Wingo
2016-10-09 14:17 ` Ricardo Wurmus
2016-10-10 12:50 ` Ludovic Courtès
2016-10-07 20:24 ` [PATCH 3/3] gnu: Add CUPS service Andy Wingo
2016-10-08 8:37 ` Andy Wingo
2016-10-09 13:02 ` Christopher Allan Webber
2016-10-09 14:37 ` Ricardo Wurmus
2016-10-10 8:32 ` Clément Lassieur
2016-10-10 8:55 ` Andy Wingo
2016-10-10 21:00 ` Ludovic Courtès [this message]
2016-10-09 14:14 ` [PATCH 1/3] gnu: cups-filters: Look for test page in own output dir Ricardo Wurmus
-- strict thread matches above, loose matches on Subject: below --
2016-10-10 13:29 Andy Wingo
2016-10-10 13:30 ` [PATCH 3/3] gnu: Add CUPS service Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87shs3gbrg.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=clement@lassieur.org \
--cc=guix-devel@gnu.org \
--cc=wingo@igalia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.