aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2024-06-16 12:13:30 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2024-06-16 12:13:30 +0900
commita0ed10aa2a780894c8f63bd4bde218d56eba411e (patch)
tree12581ba8f475a73c7c26a7a6336797d98741a86a
parent5931a79a5a915035e01b9fb22a3edfde7895e424 (diff)
Add let-values to `do` syntax
-rw-r--r--algebraic-structures.monad.scm8
1 files changed, 7 insertions, 1 deletions
diff --git a/algebraic-structures.monad.scm b/algebraic-structures.monad.scm
index 80bde36..dd9b850 100644
--- a/algebraic-structures.monad.scm
+++ b/algebraic-structures.monad.scm
@@ -7,7 +7,7 @@
M)
(import-for-syntax matchable
(chicken syntax)
- (only (srfi 1) last))
+ (only (srfi 1) every last))
(define-syntax do
(ir-macro-transformer
@@ -27,6 +27,12 @@
(symbol? let-stx) (compare let-stx (inject 'let))
(symbol? =-stx) (compare =-stx (inject '=)))
`((lambda (,var) ,acc) ,expr))
+ ((and (list? var)
+ (every symbol? var)
+ (symbol? let-stx) (compare let-stx (inject 'let-values))
+ (symbol? =-stx) (compare =-stx (inject '=)))
+ `(call-with-values (lambda () ,expr)
+ (lambda ,var ,acc)))
(else
`(>>= ,binding (lambda (_) ,acc))))]
[expr