From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Any disadvantages of using put/get instead of defvar? Date: Fri, 21 Feb 2014 12:49:22 +0100 Message-ID: <871tywheil.fsf@thinkpad-t61.fritz.box> References: <87ob218lsu.fsf@thinkpad-t61.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1392983388 26861 80.91.229.3 (21 Feb 2014 11:49:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 21 Feb 2014 11:49:48 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 21 12:49:56 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 1WGoc7-0004N9-Sq for geh-help-gnu-emacs@m.gmane.org; Fri, 21 Feb 2014 12:49:55 +0100 Original-Received: from localhost ([::1]:43967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGoc7-00060n-Ba for geh-help-gnu-emacs@m.gmane.org; Fri, 21 Feb 2014 06:49:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGobp-0005tE-Rt for help-gnu-emacs@gnu.org; Fri, 21 Feb 2014 06:49:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGobj-0007cG-LW for help-gnu-emacs@gnu.org; Fri, 21 Feb 2014 06:49:37 -0500 Original-Received: from out5-smtp.messagingengine.com ([66.111.4.29]:48964) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGobj-0007c9-H8 for help-gnu-emacs@gnu.org; Fri, 21 Feb 2014 06:49:31 -0500 Original-Received: from compute2.internal (compute2.nyi.mail.srv.osa [10.202.2.42]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id A44CA20AA9; Fri, 21 Feb 2014 06:49:30 -0500 (EST) Original-Received: from frontend2 ([10.202.2.161]) by compute2.internal (MEProxy); Fri, 21 Feb 2014 06:49:30 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=from:to:cc:subject:references:date :in-reply-to:message-id:mime-version:content-type; s=smtpout; bh=vHN5+9YSjvIqIpwLA06zv7Zf2/U=; b=JiNgLZUT8sdnFxaPQLejulWxv6vY TtmR102tbq0R3ePmxgqc5r/sFbN+IKKxvXe5pS30+Ql0cF0PNyfxGyeABOu2ZyWo FSzOWpIkmNYzhQ2ko6lqDEYxrvXVkb352MgQdYlFTqPKK7kFUg4U9QU4EN23UIIH yZuoBfDfaB8Ci2Q= X-Sasl-enc: tmGQl+twORljN82idFhcF2QmyXmB8n2Mi6aY40BVL+W6 1392983370 Original-Received: from thinkpad-t61.fritz.box (unknown [95.88.165.230]) by mail.messagingengine.com (Postfix) with ESMTPA id 1E2F2680182; Fri, 21 Feb 2014 06:49:30 -0500 (EST) In-Reply-To: (Stefan Monnier's message of "Thu, 20 Feb 2014 20:40:08 -0500") User-Agent: Gnus/5.13001 (Ma Gnus v0.10) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.111.4.29 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:96152 Archived-At: Stefan Monnier writes: >> You could also define the variable inside the function, i.e., that's a >> buffer-local counter: >> (defun counter () >> (defvar counter-var 1) >> (setq-local counter-var (1+ counter-var))) > > I'd recommend against it. Its semantics is pretty much the same as > > (defun counter () > (defvar counter-var 1) > (setq-local counter-var (1+ counter-var))) > > except that `counter-var' will only be defined after the first call to > `counter'. 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. > And no, it's not buffer-local. Well, it becomes buffer-local as soon as someone calls `counter'. Bye, Tassilo