[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Anaphoric macros: increase visibility
From: |
Tino Calancha |
Subject: |
Re: Anaphoric macros: increase visibility |
Date: |
Sat, 14 Jan 2017 14:27:47 +0900 (JST) |
User-agent: |
Alpine 2.20 (DEB 67 2015-01-07) |
On Fri, 13 Jan 2017, Michael Heerdegen wrote:
Tino Calancha <address@hidden> writes:
Hi,
I think anaphoric macros are a nice idiom; occasionally
they allow to write very concise and clear expressions.
AFAICS, in the Emacs tree they are just introduced in ibuf-macs.el
(`ibuffer-aif', `ibuffer-awhen').
We also already have `if-let' and `when-let' in "subr-x". They are like
`aif' and `awhen' but you specify "it" explicitly.
They looks also fun. Thanks.
I wonder if it has sense to increase that family with a while-let
(maybe others in case they are useful).
From 60f26b512b191add12a0c91dc4d7ff95aba080d9 Mon Sep 17 00:00:00 2001
From: Tino Calancha <address@hidden>
Date: Sat, 14 Jan 2017 14:25:42 +0900
Subject: [PATCH] * lisp/emacs-lisp/subr-x.el (while-let): New macro.
---
lisp/emacs-lisp/subr-x.el | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 7736225b5f..5e7fdfaa09 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -141,6 +141,15 @@ when-let
(declare (indent 1) (debug if-let))
(list 'if-let bindings (macroexp-progn body)))
+(defmacro while-let (bindings &rest body)
+ "Process BINDINGS and eval BODY while all values are non-nil.
+Argument BINDINGS is a list of tuples whose car is a symbol to be
+bound and (optionally) used in BODY, and its cadr is a sexp to be
+evalled to set symbol's value. In the special case you only want
+to bind a single value, BINDINGS can just be a plain tuple."
+ (declare (indent 1) (debug t))
+ `(while (when-let ,bindings (prog1 t ,@body))))
+
(defsubst hash-table-empty-p (hash-table)
"Check whether HASH-TABLE is empty (has 0 elements)."
(zerop (hash-table-count hash-table)))
--
2.11.0
- Anaphoric macros: increase visibility, Tino Calancha, 2017/01/13
- Re: Anaphoric macros: increase visibility, Michael Heerdegen, 2017/01/13
- Re: Anaphoric macros: increase visibility,
Tino Calancha <=
- Re: Anaphoric macros: increase visibility, Michael Heerdegen, 2017/01/14
- On the naming/behavior of {if, when}-let (was Re: Anaphoric macros: increase visibility), Mark Oteiza, 2017/01/14
- Re: Anaphoric macros: increase visibility, Michael Heerdegen, 2017/01/14
- Re: Anaphoric macros: increase visibility, Tino Calancha, 2017/01/15
- Re: Anaphoric macros: increase visibility, Stefan Monnier, 2017/01/15
- Re: Anaphoric macros: increase visibility, Tino Calancha, 2017/01/15
- Re: Anaphoric macros: increase visibility, Stefan Monnier, 2017/01/15
Re: Anaphoric macros: increase visibility, Dmitri Paduchikh, 2017/01/14