aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2018-11-16 00:08:53 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2018-11-16 00:08:53 +0100
commitf482ecdb4ec3cd0ecf4698a2917e971aab31f2ac (patch)
tree8448549ee60f4d6d148c859dc091fc93a791025d
parentMade do notation support pattern matching. (diff)
downloadscheme-monad-f482ecdb4ec3cd0ecf4698a2917e971aab31f2ac.tar.gz
scheme-monad-f482ecdb4ec3cd0ecf4698a2917e971aab31f2ac.tar.xz
Add modify to (control monad state).
-rw-r--r--control/monad/state.scm7
1 files changed, 6 insertions, 1 deletions
diff --git a/control/monad/state.scm b/control/monad/state.scm
index 72a3041..603e387 100644
--- a/control/monad/state.scm
+++ b/control/monad/state.scm
@@ -2,8 +2,8 @@
#:use-module (oop goops)
#:use-module (ice-9 match)
#:use-module (control monad)
- #:export (return-state run-state get put)
#:re-export (>>= >>))
+ #:export (return-state run-state get put modify))
;; Alternative implementation of get.
@@ -66,6 +66,11 @@
"Sets st to v."
(list '() v))
+(define-stateful ((modify proc) st-list)
+ (match st-list
+ ((r s)
+ (list '() (proc s)))))
+
(define-method (run-state (st <state>) init)
"Exec state with init as starting state value and st."
((proc st) (list init init)))