help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any disadvantages of using put/get instead of defvar?


From: Tassilo Horn
Subject: Re: Any disadvantages of using put/get instead of defvar?
Date: Fri, 21 Feb 2014 12:49:22 +0100
User-agent: Gnus/5.13001 (Ma Gnus v0.10) Emacs/24.3.50 (gnu/linux)

Stefan Monnier <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]