From ada3df03e33f686467ce4e887381e8753a3e603b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sun, 27 Apr 2014 23:19:11 +0200 Subject: [PATCH] monads: Hide 'derivation-expression' and 'lower-inputs'. * guix/monads.scm: Unexport 'lower-inputs' and 'derivation-expression'. (text-file*): Add comment about the switch to 'gexp->derivation'. (lower-inputs): Add comment about its doom. (derivation-expression): Likewise. * guix/gexp.scm (lower-inputs*): Rename to... (lower-inputs): ... this. Update callers. * tests/monads.scm (derivation-expression): New procedure. * doc/guix.texi (The Store Monad): Use 'gexp->derivation' instead of 'derivation-expression'. Remove documentation of 'derivation-expression'. * guix/ui.scm (read/eval): Use THE-ROOT-MODULE so that macros are properly expanded. * tests/guix-build.sh: Use 'gexp->derivation' instead of 'derivation-expression'.monads: Hide 'derivation-expression' and 'lower-inputs'. --- doc/guix.texi | 14 +++----------- guix/gexp.scm | 5 ++--- guix/monads.scm | 8 ++++---- guix/ui.scm | 2 +- tests/guix-build.sh | 7 ++++--- tests/monads.scm | 3 +++ 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index bbfdce51fa..3ae2b7e00b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -1868,11 +1868,12 @@ Consider this ``normal'' procedure: Using @code{(guix monads)}, it may be rewritten as a monadic function: +@c FIXME: Find a better example, one that uses 'mlet'. @example (define (sh-symlink) ;; Same, but return a monadic value. - (mlet %store-monad ((sh (package-file bash "bin"))) - (derivation-expression "sh" `(symlink ,sh %output)))) + (gexp->derivation "sh" + #~(symlink (string-append #$bash "/bin/bash") #$output))) @end example There are two things to note in the second version: the @code{store} @@ -1973,15 +1974,6 @@ directory of @var{package}. When @var{file} is omitted, return the name of the @var{output} directory of @var{package}. @end deffn -@deffn {Monadic Procedure} derivation-expression @var{name} @var{exp} @ - [#:system (%current-system)] [#:inputs '()] @ - [#:outputs '("out")] [#:hash #f] @ - [#:hash-algo #f] [#:env-vars '()] [#:modules '()] @ - [#:references-graphs #f] [#:guile-for-build #f] -Monadic version of @code{build-expression->derivation} -(@pxref{Derivations}). -@end deffn - @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}] Monadic version of @code{package-derivation} (@pxref{Defining Packages}). diff --git a/guix/gexp.scm b/guix/gexp.scm index 9dd83f5370..01084c2620 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -66,10 +66,9 @@ (define-record-type (define raw-derivation (store-lift derivation)) -(define (lower-inputs* inputs) +(define (lower-inputs inputs) "Turn any package from INPUTS into a derivation; return the corresponding input list as a monadic value." - ;; XXX: This is like 'lower-inputs' but without the "name" part in tuples. (with-monad %store-monad (sequence %store-monad (map (match-lambda @@ -101,7 +100,7 @@ (define* (gexp->derivation name exp (define %modules modules) (define outputs (gexp-outputs exp)) - (mlet* %store-monad ((inputs (lower-inputs* (gexp-inputs exp))) + (mlet* %store-monad ((inputs (lower-inputs (gexp-inputs exp))) (sexp (gexp->sexp exp #:outputs outputs)) (builder (text-file (string-append name "-builder") (object->string sexp))) diff --git a/guix/monads.scm b/guix/monads.scm index db8b645402..0e99cb37f1 100644 --- a/guix/monads.scm +++ b/guix/monads.scm @@ -57,9 +57,7 @@ (define-module (guix monads) text-file* package-file package->derivation - built-derivations - derivation-expression - lower-inputs) + built-derivations) #:replace (imported-modules compiled-modules)) @@ -356,6 +354,7 @@ (define (builder inputs) (lambda (port) (display ,(computed-text text inputs) port)))) + ;; TODO: Rewrite using 'gexp->derivation'. (mlet %store-monad ((inputs (lower-inputs inputs))) (derivation-expression name (builder inputs) #:inputs inputs))) @@ -376,7 +375,7 @@ (define* (package-file package (define (lower-inputs inputs) "Turn any package from INPUTS into a derivation; return the corresponding input list as a monadic value." - ;; XXX: Should probably be in (guix packages). + ;; XXX: This procedure is bound to disappear with 'derivation-expression'. (with-monad %store-monad (sequence %store-monad (map (match-lambda @@ -390,6 +389,7 @@ (define (lower-inputs inputs) inputs)))) (define derivation-expression + ;; XXX: This procedure is superseded by 'gexp->derivation'. (store-lift build-expression->derivation)) (define package->derivation diff --git a/guix/ui.scm b/guix/ui.scm index 944c9f87fa..259dddd481 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -241,7 +241,7 @@ (define (read/eval str) str args))))) (catch #t (lambda () - (eval exp the-scm-module)) + (eval exp the-root-module)) (lambda args (leave (_ "failed to evaluate expression `~a': ~s~%") exp args))))) diff --git a/tests/guix-build.sh b/tests/guix-build.sh index d66e132c1f..e0c774d055 100644 --- a/tests/guix-build.sh +++ b/tests/guix-build.sh @@ -1,5 +1,5 @@ # GNU Guix --- Functional package management for GNU -# Copyright © 2012, 2013 Ludovic Courtès +# Copyright © 2012, 2013, 2014 Ludovic Courtès # # This file is part of GNU Guix. # @@ -75,7 +75,8 @@ then false; else true; fi # Invoking a monadic procedure. guix build -e "(begin - (use-modules (guix monads) (guix utils)) + (use-modules (guix gexp)) (lambda () - (derivation-expression \"test\" '(mkdir %output))))" \ + (gexp->derivation \"test\" + (gexp (mkdir (ungexp output))))))" \ --dry-run diff --git a/tests/monads.scm b/tests/monads.scm index b51e705f01..82f4b9989c 100644 --- a/tests/monads.scm +++ b/tests/monads.scm @@ -108,6 +108,9 @@ (define (g x) guile))) #:guile-for-build (package-derivation %store %bootstrap-guile))) +(define derivation-expression + (@@ (guix monads) derivation-expression)) + (test-assert "mlet* + derivation-expression" (run-with-store %store (mlet* %store-monad ((guile (package-file %bootstrap-guile "bin/guile"))