From: Rob Thorpe
Subject: Making a local variable like "static" in C
Date: 
Message-ID: <1168547484.941415.17720@p59g2000hsd.googlegroups.com>
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?

From: Tim Bradshaw
Subject: Re: Making a local variable like "static" in C
Date: 
Message-ID: <1168549617.819800.183260@k58g2000hse.googlegroups.com>
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
From: jayessay
Subject: Re: Making a local variable like "static" in C
Date: 
Message-ID: <m3mz4pnvi4.fsf@rigel.goldenthreadtech.com>
"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
From: Kjetil Svalastog Matheussen
Subject: Re: Making a local variable like "static" in C
Date: 
Message-ID: <Pine.LNX.4.58.0701112153270.11083@notam02.uio.no>
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))
From: Pascal Costanza
Subject: Re: Making a local variable like "static" in C
Date: 
Message-ID: <50p15vF1h247pU1@mid.individual.net>
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/