[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Any disadvantages of using put/get instead of defvar?
From: |
Helmut Eller |
Subject: |
Re: Any disadvantages of using put/get instead of defvar? |
Date: |
Fri, 21 Feb 2014 14:45:40 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
On Fri, Feb 21 2014, Tassilo Horn wrote:
> Another way would be
>
> (progn
> (defvar bar-foo 0)
> (defun bar ()
> ;; do stuff with bar-foo
> ))
>
> which has the possible benefit that bar-foo is defined as soon as the
> file is loaded instead being undefined until the first `bar' call. And
> the wrapping in a `progn' probably reduces the chance that you move
> `bar' somewhere and forget `bar-foo'.
With lexical-binding
(let ((foo 0))
(defun bar ()
...))
is also an option. This has the advantage that it uses the shortest
names and foo is actually a lexically scoped variable that is not
accessible outside of bar. One disadvantage is that it's not possible to
look at foo, say for debugging purposes.
Helmut
- Re: Any disadvantages of using put/get instead of defvar?, (continued)
Re: Any disadvantages of using put/get instead of defvar?, Oleh, 2014/02/21
Re: Any disadvantages of using put/get instead of defvar?, Sebastian Wiesner, 2014/02/21