From 2af715fe4ac1ed36a4809307f5a177c1e6161574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 23 Dec 2019 02:17:26 +0100 Subject: Add awhen. --- module/util.scm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'module/util.scm') diff --git a/module/util.scm b/module/util.scm index 0d4d20d6..0bbab9bc 100644 --- a/module/util.scm +++ b/module/util.scm @@ -11,7 +11,7 @@ quote? re-export-modules use-modules* - -> set aif + -> set aif awhen tree-map let-lazy let-env) #:replace (let* set! define-syntax when unless if)) @@ -44,6 +44,7 @@ ((@ (guile) if) p t (begin f ...))])) + (define-syntax aif (lambda (stx) (syntax-case stx () @@ -51,6 +52,21 @@ (with-syntax ((it (datum->syntax stx 'it))) #'(let ((it condition)) (if it true-clause false-clause)))]))) + +(define-syntax awhen + (lambda (stx) + (syntax-case stx () + [(_ condition body ...) + (with-syntax ((it (datum->syntax stx 'it))) + #'(let ((it condition)) + (when it body ...)))]))) + +#; +(define-macro (awhen pred . body) + `(let ((it ,pred)) + (when it + ,@body))) + (define-public upstring->symbol (compose string->symbol string-upcase)) -- cgit v1.2.3