I want to make a variable in a function that:-
* Retains it's old value when the function is called again
* Is not a global variable and preferably not a special variable
How can this be done?
Rob Thorpe wrote:
> I want to make a variable in a function that:-
> * Retains it's old value when the function is called again
> * Is not a global variable and preferably not a special variable
>
> How can this be done?
If you want to avoid closures (which is the easy way) you can also do
this with a macro which expands to SYMBOL-MACROLET.
From: Thomas A. Russ
Subject: Re: Making a local variable like "static" in C
Date:
Message-ID: <ymivejddtuc.fsf@sevak.isi.edu>
"Rob Thorpe" <·······@realworldtech.com> writes:
> I want to make a variable in a function that:-
> * Retains it's old value when the function is called again
> * Is not a global variable and preferably not a special variable
>
> How can this be done?
Closures:
(let ((static-variable 'initial-value))
(defun my-function (...)
(...)))
Simple example:
(let ((counter 0))
(defun call-counter ()
(incf counter)))
(call-counter) => 1
(call-counter) => 2
(call-counter) => 3
--
Thomas A. Russ, USC/Information Sciences Institute
"Rob Thorpe" <·······@realworldtech.com> writes:
> I want to make a variable in a function that:-
> * Retains it's old value when the function is called again
> * Is not a global variable and preferably not a special variable
>
> How can this be done?
Are you saying that something like:
(let (my-var)
(defun my-func (...) ...))
is not sufficient?
/Jon
--
'j' - a n t h o n y at romeo/charley/november com
On Thu, 11 Jan 2007, Rob Thorpe wrote:
> I want to make a variable in a function that:-
> * Retains it's old value when the function is called again
> * Is not a global variable and preferably not a special variable
>
> How can this be done?
>
>
Hmm, something like this, perhaps:
(let ((a 9))
(defun foo ()
a))
Rob Thorpe wrote:
> I want to make a variable in a function that:-
> * Retains it's old value when the function is called again
> * Is not a global variable and preferably not a special variable
>
> How can this be done?
load-time-value
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/