From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Harald Hanche-Olsen Newsgroups: gmane.emacs.devel Subject: Re: emacs lisp syntax rfc: (cond (EXPR => (lambda (X) ...))) Date: Sun, 02 Jan 2011 23:52:34 +0100 (CET) Message-ID: <20110102.235234.923991058990597855.hanche@math.ntnu.no> References: <877hengesr.fsf@ambire.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1294008770 19793 80.91.229.12 (2 Jan 2011 22:52:50 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 2 Jan 2011 22:52:50 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jan 02 23:52:46 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PZWn8-0006fG-Gb for ged-emacs-devel@m.gmane.org; Sun, 02 Jan 2011 23:52:46 +0100 Original-Received: from localhost ([127.0.0.1]:51467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PZWn7-0004zU-OD for ged-emacs-devel@m.gmane.org; Sun, 02 Jan 2011 17:52:45 -0500 Original-Received: from [140.186.70.92] (port=51169 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PZWn3-0004yJ-Eq for emacs-devel@gnu.org; Sun, 02 Jan 2011 17:52:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PZWn2-0008Ss-9Q for emacs-devel@gnu.org; Sun, 02 Jan 2011 17:52:41 -0500 Original-Received: from anne.math.ntnu.no ([129.241.15.150]:59285) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PZWn1-0008SX-Sq for emacs-devel@gnu.org; Sun, 02 Jan 2011 17:52:40 -0500 Original-Received: (qmail 19454 invoked from network); 2 Jan 2011 22:52:35 -0000 Original-Received: from gauss.math.ntnu.no (HELO localhost) (hanche@129.241.15.102) by anne.math.ntnu.no with ESMTPA; 2 Jan 2011 22:52:35 -0000 In-Reply-To: <877hengesr.fsf@ambire.localdomain> X-URL: http://www.math.ntnu.no/~hanche/ X-Mailer: Mew version 7.0.50 on Emacs 24.0.50 / Mule 6.0 (HANACHIRUSATO) X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:134182 Archived-At: [Thien-Thi Nguyen (2011-01-02 21:45:56 UTC)] > In Scheme, the expression: > > (cond (EXPR => (lambda (X) ...))) > > provides the lambda expression parameter X with the non-false > value computed from evaluating EXPR. [...] > > What do people think of adding this to Emacs Lisp? If you think you need this, I suspect the need can just as easily be covered using a macro: (defmacro acond (&rest clauses) "Anaphoric `cond': Like `cond', except the value of the condition is bound to the variable `it' during the execution of the corresponding body." ;; Bug: This macro does no error checking. `(let (it) (cond ,@(mapcar (lambda (clause) (cons (list 'setq 'it (car clause)) (cdr clause))) clauses)))) Example usage: (acond ((foo) (do-something-with it)) ((bar) (do-something-else-with it))) I learned about anaphoric macros from Paul Graham's "On Lisp". They can be very handy. - Harald