MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Variable containing code

Hi Daniel,
The easiest way I could come up with fast is this:

Use t1[1] instead of t1:

t1[1]:= Print["Hello"]

Use a storage variable:

store = DownValues[t1];

Put then 

t2 := store[[1, 2]]

Then you could change t1, and t2 will anyway print "Hello" each time you
evaluate it.

There are probably better ways.

Best regards

Ingolf Dahl

-----Original Message-----
From: Daniel Huber [mailto:dh at] 
Sent: 12 April 2007 12:28
To: ingolf.dahl at
Subject: [mg74978] Re: [mg74937] Variable containing code

Hi Ingolf,
unfortunately life is not so easy. t2:=t1 reevaluates t1 each time  t2 
is used. If t1 is changing in between t2 is changed too. What is looked 
for, is a way to get the value of t1 into the definition of t2 without 
evaluating it.

Ingolf Dahl wrote:
> Maybe you could try with
> t2 := t1;
> or am I missing something?
> Best regards
> Ingolf Dahl
> Sweden
> -----Original Message-----
> From: dh [mailto:dh at] 
> Sent: 12 April 2007 10:47
> To: mathgroup at
> Subject: [mg74937] Variable containing code
> Hello,
> how can one get at the value of a variable if this value is executable 
> code? E.g. consider variable t1:= Print["Hello"]. How can I set the 
> value of a second variable t2 to the value of t1 without executing the
> Daniel


Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:dh at>

  • Prev by Date: Re: Clean-up code for packages
  • Next by Date: Re: bug in Integrate (5.2)
  • Previous by thread: Re: Variable containing code
  • Next by thread: Re: Variable containing code