unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: Emacs developers <emacs-devel@gnu.org>,
	Tino Calancha <tino.calancha@gmail.com>
Subject: Re: Anaphoric macros: increase visibility
Date: Sat, 14 Jan 2017 14:27:47 +0900 (JST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1701141422370.4011@calancha-pc> (raw)
In-Reply-To: <87wpdyivvf.fsf@web.de>



On Fri, 13 Jan 2017, Michael Heerdegen wrote:

> Tino Calancha <tino.calancha@gmail.com> 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 <tino.calancha@gmail.com>
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




  parent reply	other threads:[~2017-01-14  5:27 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-13  8:39 Anaphoric macros: increase visibility Tino Calancha
2017-01-13 19:48 ` Michael Heerdegen
2017-01-14  2:30   ` Rolf Ade
2017-01-14  2:48     ` Rolf Ade
2017-01-14  3:03     ` Noam Postavsky
2017-01-14  4:13       ` Richard Copley
2017-01-14  5:27   ` Tino Calancha [this message]
2017-01-15  0:39     ` Michael Heerdegen
2017-01-15  2:24       ` On the naming/behavior of {if, when}-let (was Re: Anaphoric macros: increase visibility) Mark Oteiza
2017-01-15  2:26       ` Anaphoric macros: increase visibility Michael Heerdegen
2017-01-15 10:24       ` Tino Calancha
2017-01-15 15:32         ` Stefan Monnier
2017-01-16  2:44           ` Tino Calancha
2017-01-16  3:59             ` Stefan Monnier
2017-01-14  6:25   ` Dmitri Paduchikh
2017-01-14  7:56     ` Tino Calancha
2017-01-14 10:15       ` Dmitri Paduchikh
2017-01-15  0:29         ` Michael Heerdegen
2017-01-15  2:03           ` Dmitri Paduchikh
2017-01-15  2:16             ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1701141422370.4011@calancha-pc \
    --to=tino.calancha@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=michael_heerdegen@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).