[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Any disadvantages of using put/get instead of defvar?
From: |
Oleh |
Subject: |
Re: Any disadvantages of using put/get instead of defvar? |
Date: |
Fri, 21 Feb 2014 10:12:44 +0100 |
>> 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)))
>
Thanks, Tassilo,
But doesn't `defvar` introduce overhead this way?
I've looked at `(symbol-function 'counter)` and `(byte-compile 'counter)`
and it seems that it does.
regards,
Oleh
- Any disadvantages of using put/get instead of defvar?, Oleh, 2014/02/20
- Re: Any disadvantages of using put/get instead of defvar?,
Oleh <=
- Re: Any disadvantages of using put/get instead of defvar?, Tassilo Horn, 2014/02/21
- Re: Any disadvantages of using put/get instead of defvar?, Oleh, 2014/02/21
- Re: Any disadvantages of using put/get instead of defvar?, Andreas Röhler, 2014/02/21
- Re: Any disadvantages of using put/get instead of defvar?, Tassilo Horn, 2014/02/21
- Message not available
- Re: Any disadvantages of using put/get instead of defvar?, Helmut Eller, 2014/02/21
- Re: Any disadvantages of using put/get instead of defvar?, Sebastian Wiesner, 2014/02/21