aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-07-16 23:42:50 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-16 23:42:50 +0200
commit5a813a63a3d03dd62d5167df11700e7c613b63f3 (patch)
tree5233e6a7ffe7335376753faa92aadef53fe007db
parentAdd break/all. (diff)
downloadcalp-5a813a63a3d03dd62d5167df11700e7c613b63f3.tar.gz
calp-5a813a63a3d03dd62d5167df11700e7c613b63f3.tar.xz
Add (hnh util values).
-rw-r--r--module/hnh/util/values.scm27
1 files changed, 27 insertions, 0 deletions
diff --git a/module/hnh/util/values.scm b/module/hnh/util/values.scm
new file mode 100644
index 00000000..79f06cff
--- /dev/null
+++ b/module/hnh/util/values.scm
@@ -0,0 +1,27 @@
+(define-module (hnh util values)
+ :use-module (ice-9 control)
+ :export (abort* on-fst on-snd apply/values)
+ )
+
+
+(define-syntax-rule (abort* form)
+ (call-with-values (lambda () form) abort))
+
+
+;; (on-fst (+ 2 (abort* (values 3 4))))
+;; ⇒ 5 ⇒ 4
+
+(define-syntax-rule (on-fst form)
+ (% form
+ (lambda (prompt fst . rest)
+ (apply values (prompt fst) rest))))
+
+(define-syntax-rule (on-snd form)
+ (% form
+ (lambda (prompt fst snd . rest)
+ (apply values fst (prompt snd) rest))))
+
+
+(define-syntax-rule (apply/values proc form)
+ (call-with-values (lambda () form)
+ proc))