summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2022-07-10 12:39:44 +0200
committerLudovic Courtès <ludo@gnu.org>2022-07-10 23:57:14 +0200
commit9fdc4b6c283c5aa5cf10205d87fb2c58b829b9d0 (patch)
tree9458f4783146777e11efb0de96aa6677fe5d73d0 /guix
parentbf0a646a5bcde489b602c58fbb63a93acb9d08f6 (diff)
monads: Add 'mparameterize'.
* etc/system-tests.scm (mparameterize): Move to... * guix/monads.scm (mparameterize): ... here. * tests/monads.scm ("mparameterize"): New test. * .dir-locals.el (c-mode): Add it.
Diffstat (limited to 'guix')
-rw-r--r--guix/monads.scm18
1 files changed, 17 insertions, 1 deletions
diff --git a/guix/monads.scm b/guix/monads.scm
index 6ae616aca9..0bd8ac9315 100644
--- a/guix/monads.scm
+++ b/guix/monads.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2013, 2014, 2015, 2017 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2013, 2014, 2015, 2017, 2022 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -40,6 +40,7 @@
mbegin
mwhen
munless
+ mparameterize
lift0 lift1 lift2 lift3 lift4 lift5 lift6 lift7 lift
listm
foldm
@@ -398,6 +399,21 @@ expression."
(mbegin %current-monad
mexp0 mexp* ...)))))
+(define-syntax mparameterize
+ (syntax-rules ()
+ "This form implements dynamic scoping, similar to 'parameterize', but in a
+monadic context."
+ ((_ monad ((parameter value) rest ...) body ...)
+ (let ((old-value (parameter)))
+ (mbegin monad
+ ;; XXX: Non-local exits are not correctly handled.
+ (return (parameter value))
+ (mlet monad ((result (mparameterize monad (rest ...) body ...)))
+ (parameter old-value)
+ (return result)))))
+ ((_ monad () body ...)
+ (mbegin monad body ...))))
+
(define-syntax define-lift
(syntax-rules ()
((_ liftn (args ...))