[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#30657] [PATCH] services: messaging: Prosody config supports file-li
From: |
Ludovic Courtès |
Subject: |
[bug#30657] [PATCH] services: messaging: Prosody config supports file-like objects. |
Date: |
Sat, 03 Mar 2018 15:27:52 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) |
Hi!
Clément Lassieur <address@hidden> skribis:
> Clément Lassieur <address@hidden> writes:
>
>> (define (serialize-field field-name val)
>> - (format #t "~a = ~a;\n" (uglify-field-name field-name) val))
>> + #~(string-append
>> + #$(format #f "~a = " (uglify-field-name field-name)) #$val ";\n"))
>
> #~(format #f "~a = ~a;\n" #$(uglify-field-name field-name) #$val))
>
>> (define (serialize-field-list field-name val)
>> (serialize-field field-name
>> - (with-output-to-string
>> - (lambda ()
>> - (format #t "{\n")
>> - (for-each (lambda (x)
>> - (format #t "~a;\n" x))
>> - val)
>> - (format #t "}")))))
>> + #~(string-append
>> + "{\n"
>> + #$@(map (lambda (x)
>> + #~(string-append #$x ";\n"))
>> + val)
>> + "}")))
>
> (ice-9 format) can do miracles ;-)
>
> (serialize-field field-name #~(format #f "address@hidden;\n~}}"
> address@hidden)))
Indeed, though you need to make sure (ice-9 format) is in scope on the
build side (the default ‘format’, aka. ‘simple-format’, doesn’t support
anything beyond ~a, ~s, and ~%).
>> (define (enclose-quotes s)
>> - (format #f "\"~a\"" s))
>> + #~(string-append "\"" #$s "\""))
>
> #~(format #f "\"~a\"" #$s))
It’s a case where I prefer ‘string-append’ because is ensures that
everything is a string and reports a type error if not. Conversely,
(format #f "~a" …) will silently convert anything to a string, which may
not be what you want.
> (with-imported-modules '((ice-9 format))
This would import (ice-9 format) from the host Guile into the build
environment. Thus, if you build your system with Guix on Guile 2.2.2
and I build mine on Guile 2.0.14, we end up with different derivations,
which is not desirable.
Instead, what you need is this:
> #~(begin
> (use-modules (ice-9 format))
That puts (ice-9 format) in scope, which is all you need. It’s the
(ice-9 format) of the build-side Guile that’s used.
Thanks,
Ludo’.