From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1es88s-0002AB-Gu for guix-patches@gnu.org; Sat, 03 Mar 2018 09:28:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1es88o-0001VJ-Hh for guix-patches@gnu.org; Sat, 03 Mar 2018 09:28:06 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:34094) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1es88o-0001VC-EB for guix-patches@gnu.org; Sat, 03 Mar 2018 09:28:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1es88n-00075v-VS for guix-patches@gnu.org; Sat, 03 Mar 2018 09:28:01 -0500 Subject: [bug#30657] [PATCH] services: messaging: Prosody config supports file-like objects. Resent-Message-ID: From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <87o9k6csz9.fsf@gnu.org> <20180303013308.12929-1-clement@lassieur.org> <871sh1mljz.fsf@lassieur.org> Date: Sat, 03 Mar 2018 15:27:52 +0100 In-Reply-To: <871sh1mljz.fsf@lassieur.org> ("=?UTF-8?Q?Cl=C3=A9ment?= Lassieur"'s message of "Sat, 03 Mar 2018 12:43:28 +0100") Message-ID: <87k1utb5ef.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: =?UTF-8?Q?Cl=C3=A9ment?= Lassieur Cc: 30657@debbugs.gnu.org Hi! Cl=C3=A9ment Lassieur skribis: > Cl=C3=A9ment Lassieur writes: > >> (define (serialize-field field-name val) >> - (format #t "~a =3D ~a;\n" (uglify-field-name field-name) val)) >> + #~(string-append >> + #$(format #f "~a =3D " (uglify-field-name field-name)) #$val ";\n"= )) > > #~(format #f "~a =3D ~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 =E2=80=98format=E2=80=99, aka. =E2=80=98simple-form= at=E2=80=99, doesn=E2=80=99t support anything beyond ~a, ~s, and ~%). >> (define (enclose-quotes s) >> - (format #f "\"~a\"" s)) >> + #~(string-append "\"" #$s "\"")) > > #~(format #f "\"~a\"" #$s)) It=E2=80=99s a case where I prefer =E2=80=98string-append=E2=80=99 because = is ensures that everything is a string and reports a type error if not. Conversely, (format #f "~a" =E2=80=A6) will silently convert anything to a string, whic= h 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=E2=80=99s the (ice-9 format) of the build-side Guile that=E2=80=99s used. Thanks, Ludo=E2=80=99.