From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: Dynamically constructing advice behaves strangely Date: Sun, 14 Feb 2016 16:44:03 +0100 Message-ID: <87ziv39u0s.fsf@web.de> References: <87io1r2v89.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1455464683 26043 80.91.229.3 (14 Feb 2016 15:44:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 14 Feb 2016 15:44:43 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Feb 14 16:44:34 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aUyqZ-0002rh-TV for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Feb 2016 16:44:28 +0100 Original-Received: from localhost ([::1]:51486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUyqZ-0002zQ-4X for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Feb 2016 10:44:27 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUyqN-0002xw-QB for help-gnu-emacs@gnu.org; Sun, 14 Feb 2016 10:44:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUyqK-0008Iw-GL for help-gnu-emacs@gnu.org; Sun, 14 Feb 2016 10:44:15 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:36249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUyqK-0008Ie-6E for help-gnu-emacs@gnu.org; Sun, 14 Feb 2016 10:44:12 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1aUyqH-0002gC-9k for help-gnu-emacs@gnu.org; Sun, 14 Feb 2016 16:44:09 +0100 Original-Received: from dslb-092-074-178-250.092.074.pools.vodafone-ip.de ([92.74.178.250]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 14 Feb 2016 16:44:09 +0100 Original-Received: from michael_heerdegen by dslb-092-074-178-250.092.074.pools.vodafone-ip.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 14 Feb 2016 16:44:09 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 26 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: dslb-092-074-178-250.092.074.pools.vodafone-ip.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.91 (gnu/linux) Cancel-Lock: sha1:/INNZxWnvM+Zle3XPjOTwDlptHY= 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:109165 Archived-At: Marcin Borkowski writes: > (defun add-constructed-advice (fun) > "Add a constructed advice to function foo." > (let* ((fun-name (symbol-name fun)) > (length-sym > (make-symbol (concat "length-of-" fun-name))) > (piece-of-advice-sym > (make-symbol (concat "advice-for-" fun-name))) > (piece-of-advice (lambda (orig-fun &rest args) > (apply orig-fun args) > (message "This function's name had length %s." > (symbol-value length-sym))))) Also, `length-sym' doesn't have to be an uninterned symbol here. You use lexical-binding anyway (by referring to the value of the (interned!) symbol named "length-sym". You don't even have to use a symbol with a unique name. Just use a simple (lexical) variable for the length, e.g. `advice-length', and (message "This function's name had length %s." advice-length) etc. (your piece of advice is a closure!). Michael.