Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Variables within With statement
Replies: 5   Last Post: Dec 22, 2011 4:01 AM

 Messages: [ Previous | Next ]
Re: Variables within With statement
Posted: Dec 17, 2011 1:51 AM

You could try delaying assignment of a, as follows:

In[1]:= With[{a := a = 5, b = 10 a}, a + b]

Out[1]= 55

Cheers,

Mark

On Dec 15, 9:53 am, "Harvey P. Dale" <h...@nyu.edu> wrote:
> Is there any easy way to have one variable within a With
> statement take its value from a prior variable in the same With
> statement? For example, if I evaluate With[{a = 5, b = 10 a}, a + b], I
> get 5 + 10a, and what I want is 55. I can get there like this: With[{a
> = 5}, With[{b = 10 a}, a + b]] -- which does produce 55 -- but it would
> be nicer if I could use a single With statement and get b, within it, to
> take its value from a.
>
> Thanks.
>
> Harvey

Date Subject Author
12/15/11 Harvey P. Dale
12/16/11 Simon Tyler