1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 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 (ice-9 pretty-print)
23 #:use-module (system repl repl)
24 #:use-module (system repl common)
25 #:use-module (system repl command)
26 #:use-module (system base language)
27 #:use-module (system base compile)
28 #:use-module (srfi srfi-26)
29 #:export (run-in-store
34 ;;; This modules provides a couple of REPL meta-commands that make it easier
35 ;;; to work with monadic procedures in the store monad.
39 (define* (monad-language monad run #:optional (name 'monad))
40 "Return a language with a special evaluator that causes monadic values
41 to be \"run\" in MONAD using procedure RUN."
42 (let ((scheme (lookup-language 'scheme)))
43 (define (evaluate-monadic-expression exp env)
44 (let ((mvalue (compile exp #:to 'value #:env env)))
47 (make-language #:name name
49 #:reader (language-reader scheme)
50 #:compilers (language-compilers scheme)
51 #:decompilers (language-decompilers scheme)
52 #:evaluator evaluate-monadic-expression
53 #:printer (language-printer scheme)
54 #:make-default-environment
55 (language-make-default-environment scheme))))
57 (define (store-monad-language)
58 "Return a compiler language for the store monad."
59 (let ((store (open-connection)))
60 (monad-language %store-monad
61 (cut run-with-store store <>)
64 (define-meta-command ((run-in-store guix) repl (form))
66 Run EXP through the store monad."
67 (let ((value (with-store store
68 (run-with-store store (repl-eval repl form)))))
69 (run-hook before-print-hook value)
70 (pretty-print value)))
72 (define-meta-command ((enter-store-monad guix) repl)
74 Enter a REPL for values in the store monad."
75 (let ((new (make-repl (store-monad-language))))
76 ;; Force interpretation so that our specially-crafted language evaluator
78 (repl-option-set! new 'interp #t)
81 ;;; monad-repl.scm ends here