From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.devel Subject: Re: Anaphoric macros: increase visibility Date: Sat, 14 Jan 2017 14:27:47 +0900 (JST) Message-ID: References: <87wpdyivvf.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1484371716 3705 195.159.176.226 (14 Jan 2017 05:28:36 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 14 Jan 2017 05:28:36 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: Emacs developers , Tino Calancha To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 14 06:28:31 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cSGt8-0008Q5-BL for ged-emacs-devel@m.gmane.org; Sat, 14 Jan 2017 06:28:26 +0100 Original-Received: from localhost ([::1]:46506 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cSGtB-0005AD-7z for ged-emacs-devel@m.gmane.org; Sat, 14 Jan 2017 00:28:29 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57851) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cSGse-00059x-15 for emacs-devel@gnu.org; Sat, 14 Jan 2017 00:27:56 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cSGsa-0001WG-U9 for emacs-devel@gnu.org; Sat, 14 Jan 2017 00:27:56 -0500 Original-Received: from mail-pf0-x232.google.com ([2607:f8b0:400e:c00::232]:32906) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cSGsa-0001WC-Nb for emacs-devel@gnu.org; Sat, 14 Jan 2017 00:27:52 -0500 Original-Received: by mail-pf0-x232.google.com with SMTP id y143so40012883pfb.0 for ; Fri, 13 Jan 2017 21:27:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=PGn4+IggamV6eiwdImvpAyRVZlPNokW9klZoHZWkC80=; b=gsECVD7MRzHZOjBgGpPpUlpCQX/xIZ/mdM+wKH35m9JxkU5lqIMYGzv2kMZh2Aqzzv BVZK31eGAzCRrE1FJ6nZ5kFtqolYeITtAfqxf3P6S/yo/soxQziSEW4E1Xn6bAWSSZ5C zws+sjxP/i4qL+Ct9SmnKc7L5kU/quBgJe+BXedCgSDUR/GjJB2wdesfclscGQgclBjb 47ZvxWxGKtUuOQ9iYB9Wop4Fzm5z+Ni/Z5DnY6KQYiZUKRDxdf8dFa0pX7kExinVWRdB nYqd+vTR+IlEtViFjFlCk7gvnjgfjPWZAEWc+HcNt4Poq6Y2ZZXnHcpwuk9Sq79nxGzS QeYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=PGn4+IggamV6eiwdImvpAyRVZlPNokW9klZoHZWkC80=; b=uKH/GqlRIRAiqNabNuGrJX3WgvYSDQO2c4pLPVRhBvjuK1xHycTpKwzlLBJKJaEBq1 uG55TsFCZpk+CyrQ2ZzhVqf82F3SrInJc3jg/sBu9cxieYGauK55vvO8Y/hr5AylzgZ8 DXubhn4dhLKrvMYC9t8/yKBqniEcBw5Rj3ZgzjLJ05WumaP4/smV/irJe/K1zSRhTMmd ismF7ZvlyFr9qGtEJC70JxtypQR/1z74EejETgQGnZBl1yGLqUorPx2bdj/E1tbAISmi RPxZszaIOSq33W7gOd6Rwf3x5vxjp1i38kHhPB7gbqL47YRleUSKRpr92b3PsJUHzO6R QV5w== X-Gm-Message-State: AIkVDXJDL3whHfaogzCEqsjuRMnxMjNmmzGRFKZIg25vz6yuw7nTUnfDdX9SslqrNEVBHw== X-Received: by 10.98.212.23 with SMTP id a23mr1705638pfh.18.1484371671810; Fri, 13 Jan 2017 21:27:51 -0800 (PST) Original-Received: from calancha-pc (33.94.100.220.dy.bbexcite.jp. [220.100.94.33]) by smtp.gmail.com with ESMTPSA id o12sm32679686pfg.15.2017.01.13.21.27.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jan 2017 21:27:51 -0800 (PST) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: <87wpdyivvf.fsf@web.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::232 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:211262 Archived-At: On Fri, 13 Jan 2017, Michael Heerdegen wrote: > Tino Calancha 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 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