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: Thu, 20 Feb 2014 23:24:33 +0100 Message-ID: <87ob218lsu.fsf@thinkpad-t61.fritz.box> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1392935097 4452 80.91.229.3 (20 Feb 2014 22:24:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Feb 2014 22:24:57 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Oleh Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Feb 20 23:25:05 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 1WGc3D-0005i9-OG for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Feb 2014 23:25:03 +0100 Original-Received: from localhost ([::1]:41034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGc3D-0003Wl-9F for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Feb 2014 17:25:03 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGc2w-0003V2-S2 for help-gnu-emacs@gnu.org; Thu, 20 Feb 2014 17:24:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGc2q-0002cd-NN for help-gnu-emacs@gnu.org; Thu, 20 Feb 2014 17:24:46 -0500 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:51798) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGc2q-0002cX-G8 for help-gnu-emacs@gnu.org; Thu, 20 Feb 2014 17:24:40 -0500 Original-Received: from compute4.internal (compute4.nyi.mail.srv.osa [10.202.2.44]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id EE3DC20DC6; Thu, 20 Feb 2014 17:24:39 -0500 (EST) Original-Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 20 Feb 2014 17:24:39 -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=BGW1cLhe/9Tr4v/+RKnwvSP/1wE=; b=cBO+DOn44LD7HYrkkpuoLRzIsdNi mCGElkf8sot5aYbkBWMlN9DX0HHf9w9tHRFn18tGQdf3WKL5sf5A2eG2oRkK3O0j 7ZOprd2AdAfrch7CjEGhttWEYOdMgTbVwSNKFw4bX6CDb7j92CtRYMUHeKWUK8Lm GhDNebMYPLGZaBU= X-Sasl-enc: UEmJpxpXsXDnLBr/XurCnLCZucJE/eWpEQkTEiRiZFJx 1392935079 Original-Received: from thinkpad-t61.fritz.box (unknown [95.88.165.230]) by mail.messagingengine.com (Postfix) with ESMTPA id 1165E6801A7; Thu, 20 Feb 2014 17:24:38 -0500 (EST) In-Reply-To: (Oleh's message of "Thu, 20 Feb 2014 18:04:52 +0100") 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.28 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:96145 Archived-At: Oleh writes: > The situation is that I have a function that uses one global variable. > It's for sure that no other function will want this variable. In an > effort to have all code in one place I want to move from: > > (defvar bar-foo 1) > (defun bar () > ;; use bar-foo here > ) > > to: > > (defun bar () > (let ((foo (or (get 'bar 'foo) 1))) > ;; use foo here > )) > > So the advantage is that I can move and rename the function without > worry that the function/variable coupling will break, because now > everything is inside one function. 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))) Bye, Tassilo