1

The command With[{x = 1}, x] outputs 1.

The command t = x; With[{x = 1}, t] outputs x.

I expected this second input to give the same answer. How can I modify my code so it behaves in this way?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Tom
  • 3,416
  • 1
  • 18
  • 33

2 Answers2

5
t = x; With[{x = 1}, Evaluate[t]]
Coolwater
  • 20,257
  • 3
  • 35
  • 64
4

I think you are confusing the behaviour of With and Block

t = x; Block[{x = 1}, t]
(* 1 *)
ybeltukov
  • 43,673
  • 5
  • 108
  • 212