From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eVxPz-0006Oa-U9 for guix-patches@gnu.org; Mon, 01 Jan 2018 05:34:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eVxPx-0004Vh-HM for guix-patches@gnu.org; Mon, 01 Jan 2018 05:34:07 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:50579) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eVxPx-0004Va-EO for guix-patches@gnu.org; Mon, 01 Jan 2018 05:34:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eVxPx-0000uR-6h for guix-patches@gnu.org; Mon, 01 Jan 2018 05:34:05 -0500 Subject: [bug#29926] [PATCH 1/5] gexp: Add 'eval-gexp'. Resent-Message-ID: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eVxPi-0006LF-HQ for guix-patches@gnu.org; Mon, 01 Jan 2018 05:33:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eVxPf-0004Mp-Be for guix-patches@gnu.org; Mon, 01 Jan 2018 05:33:50 -0500 Received: from rezeros.cc ([45.76.207.221]:56206) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eVxPe-0004LU-TQ for guix-patches@gnu.org; Mon, 01 Jan 2018 05:33:47 -0500 From: =?UTF-8?Q?=E5=AE=8B=E6=96=87=E6=AD=A6?= Date: Mon, 1 Jan 2018 18:33:32 +0800 Message-Id: <20180101103336.8613-2-iyzsong@member.fsf.org> In-Reply-To: <20180101103336.8613-1-iyzsong@member.fsf.org> References: <20180101103336.8613-1-iyzsong@member.fsf.org> 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: 29926@debbugs.gnu.org * guix/gexp.scm (eval-gexp): New procedure. --- guix/gexp.scm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/guix/gexp.scm b/guix/gexp.scm index f005c4d29..9709c5ecb 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -76,6 +76,7 @@ gexp->derivation gexp->file gexp->script + eval-gexp text-file* mixed-text-file file-union @@ -1167,6 +1168,21 @@ and '%load-compiled-path' to honor EXP's imported modules." #:local-build? #t #:substitutable? #f))))) +(define* (eval-gexp exp #:optional (name "computed-value")) + "Return as a monadic value the EXP (a gexp) evaluate to. This is +implemented by building a store file NAME that contains the textual +representation of EXP's value, and then @code{read} from it." + (mlet* %store-monad + ((drv (gexp->derivation + name + (gexp (with-output-to-file (ungexp output) + (lambda () + (write (eval (quote (ungexp exp)) (current-module)))))) + #:local-build? #t + #:substitutable? #f)) + (_ (built-derivations (list drv)))) + (return (call-with-input-file (derivation->output-path drv) read)))) + (define* (text-file* name #:rest text) "Return as a monadic value a derivation that builds a text file containing all of TEXT. TEXT may list, in addition to strings, objects of any type that -- 2.13.3