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: Stefan Monnier
Subject: Re: Any disadvantages of using put/get instead of defvar?
Date: Thu, 20 Feb 2014 20:40:08 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> 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'.

And no, it's not buffer-local.


        Stefan




reply via email to

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