unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: 宋文武 <iyzsong@member.fsf.org>
To: 29926@debbugs.gnu.org
Subject: [bug#29926] [PATCH 1/5] gexp: Add 'eval-gexp'.
Date: Mon,  1 Jan 2018 18:33:32 +0800	[thread overview]
Message-ID: <20180101103336.8613-2-iyzsong@member.fsf.org> (raw)
In-Reply-To: <20180101103336.8613-1-iyzsong@member.fsf.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

  reply	other threads:[~2018-01-01 10:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-01 10:33 [bug#29928] [PATCH 0/5] Optimize profile hooks 宋文武
2018-01-01 10:33 ` 宋文武 [this message]
2018-01-01 10:33 ` [bug#29927] [PATCH 2/5] profiles: info-dir-file: Don't consider unwanted manifest entries 宋文武
2018-01-01 10:33 ` [bug#29925] [PATCH 3/5] guix package: Disable profile hooks on dry runs 宋文武
2018-01-01 13:36   ` Danny Milosavljevic
2018-01-01 10:33 ` [bug#29930] [PATCH 4/5] profiles: Filter out unwanted manifest entries for profile hooks 宋文武
2018-01-01 10:33 ` [bug#29929] [PATCH 5/5] profiles: Sort manifest inputs " 宋文武
2018-01-01 13:38   ` Danny Milosavljevic
2018-01-11 22:45 ` [bug#29928] [PATCH 0/5] Optimize " Ludovic Courtès
2018-01-19 14:42   ` 宋文武
2018-01-19 16:04     ` Ludovic Courtès
2018-01-20 12:52       ` 宋文武
2021-05-11 13:34 ` Leo Prikler
2021-05-12 11:12   ` bug#29925: " 宋文武

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

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180101103336.8613-2-iyzsong@member.fsf.org \
    --to=iyzsong@member.fsf.org \
    --cc=29926@debbugs.gnu.org \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).