GNU bug report logs - #30657
Add support for file-like objects to the Prosody configuration

Previous Next

Package: guix-patches;

Reported by: Clément Lassieur <clement <at> lassieur.org>

Date: Wed, 28 Feb 2018 22:27:02 UTC

Severity: normal

Done: Clément Lassieur <clement <at> lassieur.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: ludo <at> gnu.org (Ludovic Courtès)
To: Clément Lassieur <clement <at> lassieur.org>
Cc: 30657 <at> debbugs.gnu.org
Subject: [bug#30657] [PATCH] services: messaging: Prosody config supports file-like objects.
Date: Sat, 03 Mar 2018 15:27:52 +0100
Hi!

Clément Lassieur <clement <at> lassieur.org> skribis:

> Clément Lassieur <clement <at> lassieur.org> 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 "{\n~@{~a;\n~}}" #$@val)))

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’.




This bug report was last modified 7 years and 167 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.