1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (guix monad-repl)
20 #:use-module (guix store)
21 #:use-module (guix monads)
22 #:use-module (guix utils)
23 #:use-module (guix packages)
24 #:use-module (ice-9 pretty-print)
25 #:use-module (system repl repl)
26 #:use-module (system repl common)
27 #:use-module (system repl command)
28 #:use-module (system base language)
29 #:use-module (system base compile)
30 #:use-module (srfi srfi-26)
31 #:export (run-in-store
36 ;;; This modules provides a couple of REPL meta-commands that make it easier
37 ;;; to work with monadic procedures in the store monad.
41 (define* (monad-language monad run #:optional (name 'monad))
42 "Return a language with a special evaluator that causes monadic values
43 to be \"run\" in MONAD using procedure RUN."
44 (let ((scheme (lookup-language 'scheme)))
45 (define (evaluate-monadic-expression exp env)
46 (let ((mvalue (compile exp #:to 'value #:env env)))
49 (make-language #:name name
51 #:reader (language-reader scheme)
52 #:compilers (language-compilers scheme)
53 #:decompilers (language-decompilers scheme)
54 #:evaluator evaluate-monadic-expression
55 #:printer (language-printer scheme)
56 #:make-default-environment
57 (language-make-default-environment scheme))))
59 (define* (default-guile-derivation store #:optional (system (%current-system)))
60 "Return the derivation of the default "
61 (package-derivation store (default-guile) system))
63 (define (store-monad-language store)
64 "Return a compiler language for the store monad using STORE."
65 (let ((guile (or (%guile-for-build)
66 (default-guile-derivation store))))
67 (monad-language %store-monad
68 (cut run-with-store store <>
69 #:guile-for-build guile)
72 (define-meta-command ((run-in-store guix) repl (form))
74 Run EXP through the store monad."
76 (let* ((guile (or (%guile-for-build)
77 (default-guile-derivation store)))
78 (value (run-with-store store (repl-eval repl form)
79 #:guile-for-build guile)))
80 (run-hook before-print-hook value)
81 (pretty-print value))))
83 (define-meta-command ((enter-store-monad guix) repl)
85 Enter a REPL for values in the store monad."
87 (let ((new (make-repl (store-monad-language store))))
88 ;; Force interpretation so that our specially-crafted language evaluator
90 (repl-option-set! new 'interp #t)
93 ;;; monad-repl.scm ends here