blob: 79f06cff349b95914d1cd29ff0890d07dd83c972 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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))
|