From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: around advice: why does (and ad-do-it nil) return t? Date: Mon, 13 Feb 2012 21:18:59 -0700 Message-ID: References: <81zkcm6g2x.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1329193088 9808 80.91.229.3 (14 Feb 2012 04:18:08 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 14 Feb 2012 04:18:08 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 14 05:18:07 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Rx9q8-00087X-RQ for geh-help-gnu-emacs@m.gmane.org; Tue, 14 Feb 2012 05:18:05 +0100 Original-Received: from localhost ([::1]:50888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rx9q5-0001ci-OG for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Feb 2012 23:18:01 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:42389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rx9q1-0001cS-4D for help-gnu-emacs@gnu.org; Mon, 13 Feb 2012 23:17:58 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rx9pz-0008BQ-Dj for help-gnu-emacs@gnu.org; Mon, 13 Feb 2012 23:17:56 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:46754) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rx9pz-0008As-6j for help-gnu-emacs@gnu.org; Mon, 13 Feb 2012 23:17:55 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Rx9px-0007x6-Mr for help-gnu-emacs@gnu.org; Tue, 14 Feb 2012 05:17:53 +0100 Original-Received: from c-71-237-25-24.hsd1.co.comcast.net ([71.237.25.24]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 14 Feb 2012 05:17:53 +0100 Original-Received: from kevin.d.rodgers by c-71-237-25-24.hsd1.co.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 14 Feb 2012 05:17:53 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 75 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: c-71-237-25-24.hsd1.co.comcast.net User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.26) Gecko/20120129 Thunderbird/3.1.18 In-Reply-To: <81zkcm6g2x.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:83744 Archived-At: On 2/13/12 6:03 AM, Jambunathan K wrote: > Leo Alekseyev writes: > >> Consider the following code: >> >> (defun foobar () t) >> (defadvice foobar (around foobar-advice activate) >> (and ad-do-it nil)) >> >> Evaluating the advised foobar seems to return t. Why? Naively, one >> expects (and [whatever] nil) to evaluate to nil! > > One possible reason could be this: > > (info "(elisp) Around-Advice") > ,---- > | -- Variable: ad-do-it > | This is not really a variable, rather a place-holder that looks > | like a variable. You use it in around-advice to specify the place > | to run the function's original definition and other "earlier" > | around-advice. > `---- > > May be you are looking for ad-return-value. > > (info "(elisp) Defining Advice") > ,---- > | -- Variable: ad-return-value > | While advice is executing, after the function's original > | definition has been executed, this variable holds its return > | value, which will ultimately be returned to the caller after > | finishing all the advice. After-advice and around-advice can > | arrange to return some other value by storing it in this variable. > `---- Exactly. The advised function always returns ad-return-value (which the various pieces of advice may alter). As explained in the "Combined Definition" node of the Elisp manual: ---------------------------------------------------------------------- Suppose that a function has N pieces of before-advice (numbered from 0 through N-1), M pieces of around-advice and K pieces of after-advice. Assuming no piece of advice is protected, the combined definition produced to implement the advice for a function looks like this: (lambda ARGLIST [ [ADVISED-DOCSTRING] [(interactive ...)] ] (let (ad-return-value) before-0-body-form... .... before-N-1-body-form... around-0-body-form... around-1-body-form... .... around-M-1-body-form... (setq ad-return-value apply original definition to ARGLIST) end-of-around-M-1-body-form... .... end-of-around-1-body-form... end-of-around-0-body-form... after-0-body-form... .... after-K-1-body-form... ad-return-value)) ---------------------------------------------------------------------- Basically, ad-do-it expands to (setq ad-return-value apply original definition to ARGLIST) -- Kevin Rodgers Denver, Colorado, USA