From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Any disadvantages of using put/get instead of defvar? Date: Fri, 21 Feb 2014 09:41:00 -0500 Message-ID: References: <87ob218lsu.fsf@thinkpad-t61.fritz.box> <871tywheil.fsf@thinkpad-t61.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1392993714 22747 80.91.229.3 (21 Feb 2014 14:41:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 21 Feb 2014 14:41:54 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Tassilo Horn Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 21 15:42:00 2014 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 1WGrIZ-0003rd-Ua for geh-help-gnu-emacs@m.gmane.org; Fri, 21 Feb 2014 15:41:56 +0100 Original-Received: from localhost ([::1]:45012 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGrIZ-0000Vy-IE for geh-help-gnu-emacs@m.gmane.org; Fri, 21 Feb 2014 09:41:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGrHo-0008Go-Og for help-gnu-emacs@gnu.org; Fri, 21 Feb 2014 09:41:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGrHh-0004W4-Bi for help-gnu-emacs@gnu.org; Fri, 21 Feb 2014 09:41:08 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:38863) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGrHh-0004Vl-6x; Fri, 21 Feb 2014 09:41:01 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4EABK/CFFLd/o4/2dsb2JhbABEvw4Xc4IeAQEEAVYjBQsLDiYSFBgNJIgeBsEtkQoDiGGcGYFegxU X-IPAS-Result: Av4EABK/CFFLd/o4/2dsb2JhbABEvw4Xc4IeAQEEAVYjBQsLDiYSFBgNJIgeBsEtkQoDiGGcGYFegxU X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="48338710" Original-Received: from 75-119-250-56.dsl.teksavvy.com (HELO pastel.home) ([75.119.250.56]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 21 Feb 2014 09:41:00 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 1AFBA60326; Fri, 21 Feb 2014 09:41:00 -0500 (EST) In-Reply-To: <871tywheil.fsf@thinkpad-t61.fritz.box> (Tassilo Horn's message of "Fri, 21 Feb 2014 12:49:22 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 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:96159 Archived-At: > Sure (I guess you mean with the defvar before the defun), but Oleh's > goal was not to have the variable and the function separated. If he wants to keep state between invocations of the function, then that state has to be external (logically) to the function. So it is best to reflect this syntactically by making the variable external as well. If you want it syntactically "closer", you can put it between the function's name and the function itself (so it's still outside the function, but at the same time, it's still within the overall definition): (defalias 'counter (let ((counter 1)) (lambda () (setq counter (1+ counter))))) Of course, this relies on lexical-binding and is not buffer-local. Stefan