Suppose I have a variable *FOO* and
two functions: FOO and (SETF FOO) for
getting/setting *FOO* value. (SETF FOO)
function performs some checking, calculations
and then SETQs the *FOO*. Is it possible
to protect myself from doing SETF *FOO*, SETQ *FOO*
etc. accidentally ? If some other technique useful
for doing such things please let me know.
Is it worth to use slot value instead of a variable ?
--
Vladimir Zolotych ······@eurocom.od.ua
"Vladimir V. Zolotych" <······@eurocom.od.ua> writes:
> Suppose I have a variable *FOO* and
> two functions: FOO and (SETF FOO) for
> getting/setting *FOO* value. (SETF FOO)
> function performs some checking, calculations
> and then SETQs the *FOO*. Is it possible
> to protect myself from doing SETF *FOO*, SETQ *FOO*
> etc. accidentally ? If some other technique useful
> for doing such things please let me know.
> Is it worth to use slot value instead of a variable ?
1. Don't export *FOO*.
2. Closures?
;; untested
(let ((foo nil))
(defun foo ()
foo)
(defun (setf foo) (new-value)
(setf foo new-value)))
3. Use package trickery (should search through archives for example).
--
Janis Dzerins
If million people say a stupid thing it's still a stupid thing.
From: Tim Bradshaw
Subject: Re: restricting access to variable
Date:
Message-ID: <nkj3d93ny8t.fsf@tfeb.org>
Janis Dzerins <·····@latnet.lv> writes:
>
> 3. Use package trickery (should search through archives for example).
Something like (untested)
(defvar *foo*)
(defun foo ()
*foo*)
(defun (setf foo) (new)
(setf *foo* new))
(unintern '*foo*)
There may be some issue with needing an EVAL-WHEN around the UNINTERN
(don't think so though).
Closures are a lot nicer I think - no special variables for one.
--tim
Janis Dzerins wrote:
>
> 2. Closures?
Closures seems the most elegant solution.
Will use them.
Thanks to all.
--
Vladimir Zolotych ······@eurocom.od.ua